That does actually work! Thanks!
I was trying to set a function or an alias to do the most part of the writing for me (because if not, this still is faster: sudo -s; source .bash_profile; foo ).
cache(){
local OPTIND
while getopts :sdc opt
do
case $opt in
s) echo User Cache:
peso -d0 -r /Users/****/Library/Caches/com.Huyyyk.client/ | awk '{print $1}'
;;
d) echo System Cache:
peso -d0 -r /Users/****/Library/Caches/.Huyyyk/ | awk '{print $1}'
;;
c) if [ `id -u` -ne 0 ]
then warning "YOU NEED TO BE ROOT IN ORDER TO CLEAR THE CACHE"
break
fi
echo Cache:
peso -d0 -r /Users/****/Library/Caches/.Huyyyk/ | awk '{print $1 $2 $3}'
echo
echo "ARE YOU SURE YOU WANT TO CLEAR THE CACHE?"
echo "(y/n)..."
read -n1 resp
echo
echo
if [ $resp = "y" ]
then rm -rf /Users/****/Library/Caches/.Huyyyk/*
echo "CACHE HAS BEEN CLEARED"
echo
else echo ABORTED
echo
fi
;;
\?) echo "Options: -s: User cache"
echo " -d: System cache"
echo " -c: Clear cache"
;;
esac
done
}
In order to clear cache as sudo I must type:
suddo "cache -c"
I need the quotes. As I said though, great improvement.
I would not use it like this, though, because the quoting works odd this way, and so it becomes less predictable what the outcome will be and it is a sudo command after all. I would prefer to use $@ and quotes around the command...
But with $@ I don't need to use the quotes really, it works without them.
---------- Post updated at 03:34 PM ---------- Previous update was at 03:33 PM ----------
$1 - $9 these variables are the positional parameters.
$0 the name of the command currently being executed.
$# the number of positional arguments given to this
invocation of the shell.
$? the exit status of the last command executed is
given as a decimal string. When a command
completes successfully, it returns the exit status
of 0 (zero), otherwise it returns a non-zero exit
status.
$$ the process number of this shell - useful for
including in filenames, to make them unique.
$! the process id of the last command run in
the background.
$- the current options supplied to this invocation
of the shell.
$* a string containing all the arguments to the
shell, starting at $1.
$@ same as above, except when quoted.