User:Minooz/RepoSyncProj/Bash

From CDOT Wiki
< User:Minooz‎ | RepoSyncProj
Revision as of 16:02, 18 October 2010 by Minooz (talk | contribs) (Tips)
Jump to: navigation, search

Bash Scripting Help

Tutorial
Shell Programming
Linux org

Tips

  • Watch the spaces
if [ -d "$tmpInternal" ]; then
	rm -r $tmpInternal >> $dateError.txt 
elif [ -d "$tmpExternal" ]; then
	rm -r $tmExternal >> $dateError.txt 
fi


  • The increment operator in bash
while [ $revTmpInternal -lt $revInternal ]; do
	((revTmpInternal++))
done


  • to check if a file exists:
if [ -f m.patch ]; then
	rm *.patch
fi


  • To check if multiple files exist:
files=$(ls /tmp/*.cache)
if [ $files ]
then
echo "Cache files exist: do something with them"
else
echo "No cache files..."
fi