Does anyone know why this script would give me an error (only sometimes) with it saying "too many arguments"?
#!/bin/bash
HOME='/home/eric'
arrFiles=("$HOME/.kde/share/apps/kaffeine/playlists/NEW.kaffeine"\
"$HOME/.kde/share/apps/kcookiejar/cookies"\
"$HOME/.kde4/share/apps/kcookiejar/cookies")
arrDirs=("$HOME/.kde4/share/apps/RecentDocuments/*"\
"$HOME/.kde/share/apps/RecentDocuments/*"\
"$HOME/.macromedia/Flash_Player/#SharedObjects/*")
case "$1" in
trash)
rm -r $HOME/.local/share/Trash/*
echo Trash emptied
;;
history)
#Clears Files
for x in "${arrFiles[@]}"; do
if [ $x = "$x" ]; then
rm -rf $x
else
echo "nothing to empty!"
fi
done
#Clears Dirs
for x in "${arrDirs[@]}"; do
if [ $x = "$x" ]; then
echo "nothing to empty!"
else
rm -rf $x
fi
done
;;
all)
for x in "${arrFiles[@]}"; do
if [ $x = "$x" ]; then
rm -rf $x
else
echo "nothing to empty!"
fi
done
#Clears Dirs
for x in "${arrDirs[@]}"; do
if [ $x = "$x" ]; then
echo "nothing to empty!"
else
rm -rf $x
fi
done
rm -r $HOME/.local/share/Trash/*
;;
esac
Output:
root@siduxbox:/home/eric# empty trash
Trash emptied
root@siduxbox:/home/eric# empty history
/usr/bin/empty: line 31: [: too many arguments
nothing to empty!
root@siduxbox:/home/eric# empty history
nothing to empty!
nothing to empty!
nothing to empty!