Difference between revisions of "User:Minooz/RepoSyncProj/Bash"
< User:Minooz | RepoSyncProj
(→Tips) |
(→Tips) |
||
Line 22: | Line 22: | ||
− | * to check if a file exists: | + | * to check if a file exists: |
<source lang=bash> | <source lang=bash> | ||
− | if [ -f | + | if [ -f m.patch ]; then |
rm *.patch | rm *.patch | ||
+ | fi | ||
+ | </source> | ||
+ | |||
+ | |||
+ | * To check if multiple files exist: | ||
+ | <source lang=bash> | ||
+ | files=$(ls /tmp/*.cache) | ||
+ | if [ $files ] | ||
+ | then | ||
+ | echo "Cache files exist: do something with them" | ||
+ | else | ||
+ | echo "No cache files..." | ||
fi | fi | ||
</source> | </source> |
Revision as of 15:02, 18 October 2010
Bash Scripting Help
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