Writing Bash scripts is fundamental to automate and understand many tasks on common Unix-like environments. If you are new to Bash (or even Unix-like systems) you'll have it a lot easier if you take a weekend to learn some fundamental principles before starting to script your stuff. No matter how experienced you are in programming, everything you'll find regarding Bash is much easier to follow and understand if you know some things before.
IMHO, the following resources are good starting points:
To make it much easier for yourself, make sure you understand1) the following (the resources mentioned above will help you):
foobar's stderr (2) into foobar's stdout (1): foobar 2>&1
foobar's stdout (1) into a file now, all error messages will also be written into the file because stderr (2) is merged into stdout (1): foobar > ~./logfile.log 2>&1
echo "message" 1>&2
Explanation: echo prints something to stdout (1). 1>&2 merges stdout into stderr. Therefore “message” will be printed as error to stderr(2) instead of creating simple standard output – this is the way to go if you want to print a simple error message. You also need redirections if you want to use sudo.
&).find and why you need it.sed, cut, grep and find commands are available on nearly every system and are very helpful when you need to edit, find, manipulate or create files and data.if [ "$(id -u)" != "0" ]
then
echo "This script needs root privileges!" 1>&2
exit 1
fi
You'll learn the most if your scripts are doing real jobs. Create a backup script. Or try to configure your whole desktop by script to make things comfortable on freshly installed systems.