Comments on: Introduction to Bash Scripting http://tipsfor.us/2008/12/09/introduction-to-bash-scripting/ Tech Tips, Reviews, Tutorials, Occasional Rants Sat, 31 Aug 2013 15:50:35 +0000 hourly 1 https://wordpress.org/?v=4.8 By: Everett - TipsFor.us http://tipsfor.us/2008/12/09/introduction-to-bash-scripting/#comment-5074 Sat, 21 Feb 2009 06:05:22 +0000 http://www.tipsfor.us/?p=1250#comment-5074 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.”
exit;
fi

]]>
By: Everett - TipsFor.us http://tipsfor.us/2008/12/09/introduction-to-bash-scripting/#comment-4773 Wed, 17 Dec 2008 22:42:18 +0000 http://www.tipsfor.us/?p=1250#comment-4773 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 - TipsFor.us http://tipsfor.us/2008/12/09/introduction-to-bash-scripting/#comment-4686 Wed, 10 Dec 2008 19:06:35 +0000 http://www.tipsfor.us/?p=1250#comment-4686 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.

command
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:
http://www.davidpashley.com/articles/writing-robust-shell-scripts.html

]]>