Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

69 bytes added, 10:16, 3 September 2020
KEY CONCEPTS
= KEY CONCEPTS =
''A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter.<br> The various dialects of shell scripts are considered to be scripting languages. ''
Reference: https://en.wikipedia.org/wiki/Shell_script
===Creating & Executing Shell Scripts===
[[Image:ipso.png|thumb|right|500px|An '''IPSO Diagram ''' (INPUT, PROCESSING, STORAGE, OUTPUT) can be used to map-out and then list the sequence of steps to assist when coding your shell script.]]
It is recommended to '''plan''' out on a piece of paper the purpose of the shell script.<br>You can do this by creating a simple '''IPSO''' diagram (stands for '''INPUT''', '''PROCESSING''', '''STORAGE''', '''OUTPUT''').
First, list the INPUTS into the script (eg. prompting user for data, reading data from file, etc), then listing the expected OUTPUTS from the script. You can then list the steps to process the INPUT to provide the OUTPUT (including file storage).
Once you have planned your shell script by listing the sequence of steps (i.e. PROCESSING) in your script, you need to create a file (using a '''text editor''') that will contain your Linux commands.<br><br>'''NOTE:''' Avoid using filenames of already existing Linux Commands to avoid confusion. Using shell script filenames that include the file extension of the shell that the script will run within is recommended.
'''Using a Shebang Line'''
'''Setting Permissions &amp; Running a Shell Script'''
To run your shell script by name, you need to assign '''execute permissions ''' for the user.<br>To run the shell script, you can '''execute it ''' the shell script using a ''relative'', ''absolute'', or ''relative-to-home '' pathname
'''Example:<br><br><span style="font-family:courier;">chmod u+x myscript.bash<br>./myscript.bash<br>/home/username/myscript.bash<br>~/myscript.bash</span>
13,420
edits

Navigation menu