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

From CDOT Wiki
Jump to: navigation, search
(Bash Scripting Help)
(Tips)
 
(5 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
*Watch the spaces
 
*Watch the spaces
 
<source lang=bash>
 
<source lang=bash>
 
 
if [ -d "$tmpInternal" ]; then
 
if [ -d "$tmpInternal" ]; then
 
rm -r $tmpInternal >> $dateError.txt  
 
rm -r $tmpInternal >> $dateError.txt  
Line 13: Line 12:
 
fi
 
fi
 
</source>
 
</source>
 +
 +
 +
* The increment operator in bash
 +
<source lang=bash>
 +
while [ $revTmpInternal -lt $revInternal ]; do
 +
((revTmpInternal++))
 +
done
 +
</source>
 +
 +
 +
* to check if a file exists:
 +
<source lang=bash>
 +
 +
if [ -f m.patch ]; then
 +
rm *.patch
 +
fi
 +
</source>
 +
 +
 +
* 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>
 +
errors=$(ls Error*.txt 2> /dev/null | wc -l)
 +
if [ "$errors" != "0" ]; then
 +
rm Error*.txt
 +
fi
 +
</source>
 +
:Also this solution @ http://kenfallon.com/?p=4

Latest revision as of 16:27, 19 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


errors=$(ls Error*.txt 2> /dev/null | wc -l)
if [ "$errors" != "0" ]; then
	rm Error*.txt
fi
Also this solution @ http://kenfallon.com/?p=4