Comments on: Introduction to Bash Scripting Tech Tips, Reviews, Tutorials, Occasional Rants Sat, 31 Aug 2013 15:50:35 +0000 hourly 1 By: Everett - Sat, 21 Feb 2009 06:05:22 +0000 Here’s another little recipe to prompt for a y/n continue type thing:

echo “Are you sure you want to continue? (y/n)”
read a
if [[ $a != [Yy] ]]; then
echo “Exiting.”

By: Everett - Wed, 17 Dec 2008 22:42:18 +0000 I found another pitfall… on CentOS at least, you can’t declare an array using the context listed in that article!! In bash, there really AREN’T arrays… you simply treat a string as an array. E.g.

MY_ARRAY=’1 2 3 4 5′;

This can be tricky if there are file names with spaces involved…

By: Everett - Wed, 10 Dec 2008 19:06:35 +0000 One other thing that the tutorial didn’t mention was error checking in bash scripts. In bash, the $? variable contains the last returned value from a command; it goes to a non-zero number if it errors.

if [ $? -ne 0]; then echo “command failed”; exit 1; fi

could be replaced with

command || { echo “command failed”; exit 1; }

Have a look at this link for more info: