I am writing a simple bash script. My script installs ppa. The problem is I can't add two arguments. I want to write something simple like this:
./ppa.sh -i ppa:chris-lea/node.js nodejs
I tried this, but doesn't read the second argument 'nodejs'...
#! /bin/sh
# Install/add PPA or Program
while getopts ":i:e:" option;
do
case $option in
i)
echo received -i with $OPTARG
ang='sudo apt-add-repository'
;;
e)
echo received -e with $OPTARG
ang='other line'
;;
:)
echo "option -$OPTARG needs an argument"
exit
;;
*)
echo "invalid option -$OPTARG"
exit
;;
esac
# done
if [ "`echo $OPTARG | cut -d ':' -f1`" == "ppa" ]; then
echo 'is a ppa'
$ang $OPTARG ; sleep 2s && sudo apt-get update; clear
sudo apt-get -y install $OPTARG2
fi
done
-i
takes two arguments? How many does-e
take? Can they ever be mixed? – Mikel Mar 21 '14 at 12:54-e
will remove the ppa and uninstall the package – davidva Mar 21 '14 at 16:08OPTARG2=$( echo "$OPTARG" | awk '{ print $2 }')
and now work.Also enclose with double quote:
– davidva Mar 21 '14 at 18:11./ppa.sh -i "ppa:chris-lea/node.js nodejs"