Difference between revisions of "User:Minooz/RepoSyncProj/Bash"

From CDOT Wiki
Jump to: navigation, search
(Tips)
(Tips)
Line 31: Line 31:
  
  
* To check if multiple files exist:
+
* To check if multiple files exist:http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/
 
<source lang=bash>
 
<source lang=bash>
 
files=$(ls /tmp/*.cache)
 
files=$(ls /tmp/*.cache)

Revision as of 16:20, 18 October 2010

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


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