Jun 11, 2011

bash script to check if a file or a folder exist

This is a cool , I always wanted to know how to check if a file exist or not ( could submited by monk on this link http://nixcraft.com/shell-scripting/93-script-how-check-if-file-exists.html )

files="/dev/MAKEDEV /etc/makedev.d /usr/sbin/mksock"
# $i will hold single file at a time in following loop
for i in $files
if [ ! -f $i -o ! -d $i ]; then
exit 1

As I was writing shell code I ll add also some links to a bash scripting manual and another for reguraler exprssions , I have a think head but i have a tendency to complety forget who the regex work , you have to admit that cobol people gave us the worst heritage ever
For the shell scripting you can you can start from here : http://www.freeos.com/guides/lsst/
For the reg ex ( mainly sed and grep ) check this link : http://www.bsd.org/regexintro.html, for sed http://www.grymoire.com/Unix/Sed.html

No comments: