Saturday, October 2, 2010

Anyone Use Hyatt Group Legal Plan

BASH: verify existence of files or directories

temp.txt verify if the file exists:
 if [-f temp.txt] 
then echo "temp.txt exist."

else echo "temp.txt not exist."
fi
verify if the TEMP directory exists, if not create it:
 if [-d TEMP]; 
then echo "TEMP exists."

else mkdir TEMP
fi

invert if and else:
 if [! -F temp.txt] 
then echo "temp.txt not exist."

else echo "temp.txt exist."


fi if [! TEMP-d] then mkdir TEMP


else echo "TEMP exists."
fi

The following script complete verify the existence of a file passed as an argument:
 # / bin / bash # 

check that the number of arguments of the script is just a

# if [$ {#}-ne 1] then echo
"Specify the file to verification." Exit 1



fi if [-f $ {1}];
then echo "File exists."

else echo "File does not exist."


fi exit 0

0 comments:

Post a Comment