Welcome to our shell scripting tutorial series! It's required that you have a basic knowledge of the Linux Command Line, so be sure to review it before you proceed.
A shell script is a file containing lines of code for the shell to execute. The shell reads each line as if you typed them in one at a time into the terminal.
Scripting languages are interpreted, meaning that they aren't compiled into machine language. This results in less efficiency, but in exchange, we are able to more easily write our scripts.
The scripts may be written in any text editor, so simply select one with syntax highlighting - you may use Vim within your terminal, or something like Sublime Text.
We recommend that you learn a text editor while learning shell scripting. Additionally, if you want to try out Vim, head on over to our in-browser Vim tutorial series, or type
vimtutor into the command line. Taking the time to learn Vim keys will speed up your workflow immensely.
Remember that shell scripts should be short and used to manipuate files and commands. If you find that you're writing something that looks overly complex, and involves a slew of string or arithmetic operations, look into a better-suited scripting language such as Python or Perl.
For this module, we'll be using both the command line and shell scripts to give examples of what we're learning.
Anything that comes after a
$ is considered a command to be typed out on the command line. Anything following a
> symbol is a continuation of the line before.
Comment and explanation lines preceed with a
$ cd ~ # Change to home directory $ echo "Anything proceeding a > \ > symbol means it's a continuation \ > of the line before." Anything proceeding a > symbol means it's a continuation of the line before.
Lastly, anything without a preceding special character will be a snippet from a shell script file.
echo 'This is a snippet from a shell script'
Great start! Now let's move on to some important symbols covered in shell scripting.
This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.$ Check price
Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.$ Check price