Comments on Shell Scripting Part I: Getting started with bash scripting
This is the first part of a series of Linux tutorials. In writing this tutorial, I assume that you are an absolute beginner in creating Linux scripts and are very much willing to learn. During the series the level will increase, so I am sure there will be something new even for more advanced users.
11 Comment(s)
Comments
admins. when you know everything aabout (ba)sh scripting, but you'll check anyway
Hi,
In your last example, you have a ">" after the interpreter which fails if one copy and pastes your example. It should just be removed.
Ciao.
Came here to say the same thing kelmos.
I've corrected the example.
Very good, I hope you continue to teach this kind of thing! Thanks!
Thanks for the tutorial! I'm looking forward to the next one.
I cannot seem to get past the initial part of this tutorial. Am I missing something? I type in the syntax as it's displayed, (The entire shebang and the content as well...) and I save it to the Desktop but when I try to "chmod" it I get: ""chmod: cannot access ‘hello.sh’: No such file or directory"". So where am I supposed to "Save" this .sh file so that the computer/OS can recognize what I'm trying to do with it? I don't see anywhere in the tutorial that instructs me on where to save. Still going to keep trying....maybe there's something I've missed.
You may save the file anywhere on your computer, the place does not matter much. Personally I would use /tmp though. Your chmod failure means that the file does not exist, so basically you are probably not in the same directory on your console. Do a "cd" to your desktop directory on the console, or save the hello.sh file to /tmp and then do "cd /tmp" before you run the chmod command.
Most people do not add the .sh on the end of a bash script. Extensions are not used very often in Linux as the files attributes/permissions determine if the file is executable, as opposed to Windows executables, determined by the file extension.
People in #bash on freenode recommend to use #!/usr/bin/env bash as shebang line. This becomes important on systems with no fixed locations. E.g. NixOS uses atomic updates and using the enviornment for finding the bash binary will return the correct version.
I have been tinkering with Linux for a while but haven't had time to learn shell scripting. Your tutorials are perfect for me. I can follow along while at work and in between calls. Quick tip: if anyone wants to follow along and don't have a linux terminal handy, I've been using this online linux terminal with 2 browser windows side by side:
http://bellard.org/jslinux/
On to the 2nd part... :)