I didn't know which forum to post this in or how to make it "easy on the eyes"
The section below isn't exactly a "step by step" easy to follow guide.
It's a section at the Bash Scripting link in my signature.
I will be using this post as a guide for posting my questions.
Scripting
NOTE: The commands given in the scripting section are to be put into the text editor and not in the terminal unless instructed otherwise.
Bash is primarily a scripting language, so it would be a crime not to talk about scripting. Let's dive straight in with a bash script. More precisely the infamous "Hello World" script. You can create a bash script by opening your favorite text editor to edit your script and then saving it (typically the .sh file extension is used for your reference, but is not necessary. In our examples, we will be using the .sh extension).
#!/bin/bash
echo "Hello, World"The first line of the script just defines which interpreter to use. NOTE: There is no leading whitespace before #!/bin/bash. That's it, simple as that. To run a bash script you first have to have the correct file permissions. We do this with chmod command in terminal (change mode) as follows:
chmod a+x /where/i/saved/it/hello_world.sh #Gives everyone execute permissions
# OR
chmod 700 /where/i/saved/it/hello_world.sh #Gives read,write,execute permissions to the OwnerThis will give the file the appropriate permissions so that it can be executed. Now open a terminal and run the script like this:
/where/i/saved/it/hello_world.shHopefully you should have seen it print Hello, World onto your screen. If so well done! That is your first Bash script.
Bookmarks