Official website for Linux User & Developer

Shell scripting for system administrators: the basics

by Swayam Prakasha

For system administrators shell scripting can be a very useful way to drastically improve workflow. Join Swayam Prakasha to find out how you can employ some fundemental tips and techniques to make your life easier…

In the previous example, we have used numbers as patterns, but patterns can be more complex, too. Please refer to the man page of sh for more details. The following example illustrates the do…while construct:
[sourcecode language=”bash”]#!/bin/sh

# bash while loop
while [ $COUNT -gt 0 ]; do
echo Value of count is: $COUNT
Starting with an initial value of ten, we print its value till it becomes greater than zero.
When we execute the above script, the output looks like:
[sourcecode language=”bash”][root@localhost ~]# ./
Value of count is: 10
Value of count is: 9
Value of count is: 8
Value of count is: 7
Value of count is: 6
Value of count is: 5
Value of count is: 4
Value of count is: 3
Value of count is: 2
Value of count is: 1
[root@localhost ~]#
One can also execute commands inside a shell script. The following example illustrates this:
[sourcecode language=”bash”]!#/bin/sh
echo `uname -o`
When we execute this script, the following output will be displayed:
[sourcecode language=”bash”]GNU/Linux

twitter follow us
Pages: 1 2 3 4 5 6
  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.