Why to learn shell scripting?

There is a geek proverb saying “If you need to do a thing more than once, script it!“.

A good sysadmin creates and uses a lot of scripts every day, in order to do its daily tasks easier next time. A shell script is a quick and dirty mothod of combining Unix / Linux commands and launching them when necesarry, with the minimum of typing.

OK. Scripting is usefull. But why bash scripting?

Bourne-Again shell, commonly known as bash, is the default login shell in many Linux distributions. If it is not the default login shell, it can easily be installed and used on any Unix and Linux OS (as far as I know).

A good reason for learning shell scripting is its simple syntax. Shell scripting is easier to learn and use than C because it usually “means” an enumeration of commands bound together to serve a purpose. Of course, you can also use for loops or if conditionals, if you really need to. And it’s portable from one Linux distro to another.

A scripting language with a clear syntax can be easily modified and improved.

This is a sample of a short and efficient bash script:

# exec this as root!
cd /var/log
cat /dev/null > messages
echo "Your logs have been deleted!"
cd -

These commands could have been typed one by one, but it is easier to save them in the file and only exec them every time we need.

If I have convinced you about the bash’s power, read the next shell scripting article.

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!