Changes

Jump to: navigation, search

Tutorial10: Shell Scripting - Part 1

48 bytes removed, 10:02, 26 October 2020
Creating & Executing Shell Scripts
===Main Objectives of this Practice Tutorial===
:* Understand Explain the purpose of the process for '''planningshe-bang line''' prior to writing contained at the top of a shell script.
:* Understand the purpose of List rules for naming a '''she-bang line''' contained at the top of a shell Bash scriptfile.
:* Setting Explain how to set '''permissions''' for a shell script and properly how to '''execute''' a shell script.
:* Understand and use Explain the purpose of '''environment''' and '''user-defined''''''Bold text''' variables within a shell script.
:* Understand Explain the purpose of '''control flow statements''' used with shell scripts.
:* Use Explain the purpose of the '''test''' command to test various conditions.
:* Use Explain the purpose and usage of the '''if''' logic statement and the '''for''' loop statement within shell scripts.
===Tutorial Reference Material===
| style="padding-left:15px;" |Shell Scripting
* [https://searchdatacenter.techtarget.com/definition/shell-script Purpose]
* [https://www.youtube.com/watch?v=cQepf9fY6cE Creating and Running a Shell Script]<br>
Variables
* [https://opensource.com/article/19/8/what-are-environment-variables Environment]
* [https://www.cyberciti.biz/faq/bash-for-loop/#:~:text=A%20'for%20loop'%20is%20a,files%20using%20a%20for%20loop. for loop]
|colspan="1" style="padding-left:15px;" width="30%"|Brauer Instructional Videos:<ul><li>[https://www.youtube.com/watch?v=kxEP-KUhOSg&list=PLU1b1f-2Oe90TuYfifnWulINjMv_Wr16N&index=5 Bash Shell Scripting - Part 1]</li><li>[https://www.youtube.com/watch?v=cQepf9fY6cE Creating and Running a Shell Script]</li></ul>
|}
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. <br>Using shell script filenames that include the file extension of the shell that the script will run within is recommended.
'''Using a Shebang Line'''
[[Image:shebang.png|thumb|right|200px|The '''shebang line''' <u>must</u> appear on the '''first line''' and at the '''beginning''' of the shell script.]]If you are learning Bash scripting by reading other people’s code you might have noticed<br>that the first line in the scripts starts with the <span style="font-family:courier;font-weight:bold">#!</span> characters and the path to the Bash interpreter.
<i>This sequence of characters (#!) is called '''shebang''' and is used to tell the operating system<br>which interpreter to use to parse the rest of the file. </i>Reference: https://linuxize.com/post/bash-shebang/
13,420
edits

Navigation menu