Add command line argument

I would like to add the ability to change the message that is displayed when timer is finished. At present it just asks for the time I want for the alarm.

I think what I need is another command line argument.

soundfile="/usr/share/sounds/My_Sounds/Alarm-sound-buzzer.mp3"
originalVolume=$(amixer -D pulse get Master | grep -m 1 -o -E [[:digit:]]+%)
clear
amixer -D pulse sset Master 40% > /dev/null 2>&1
[ ! $1 ] && {
echo 
echo -e "   Error!! No time value given for sleep !!"
echo
echo -e "   Alarm Program 2018"
echo
echo -e "   alarm.sh [time value in seconds]"; 
echo -e "   alarm 5m   = 5 minute alarm"
echo -e "   alarm 5h   = 5 hour alarm"
echo -e "   alarm 5d   = 5 day alarm"
echo -e "   alarm 1.5m = 1 minute 30 seconds alarm"
echo 
exit 1; }
echo  -e "\033[32;5mTIMER COUNTING DOWN to $1 \033[0m"
sleep $1
{
    for ((volume = 15; volume <= 40; volume += 2)); do
        amixer -D pulse sset Master ${volume}% > /dev/null
        sleep .5
    done
} &

cvlc --play-and-exit "$soundfile" > /dev/null 2>&1
echo 'TIME IS UP.'
gxmessage -fg blue -font  'sans 20' -timeout 2 ' TIME IS UP !!'

#set back to original volume
amixer -D pulse sset Master $originalVolume > /dev/null

Yes - change ' TIME IS UP !!' to ${2:-Time is up\!} , taking advantage of "Parameter expansion - use default value". You may want to add some error checking for $2 .

Not quite what I need. I need to be able to enter something like

alarm.sh 5m Take bread out of oven.

$2 would be my message which can vary.

This works, but I have to enclose my message in double quotes.
test.sh 1 "Test print cartridge."

[ ! $2 ] && {
....
echo $2

You might want to try something like:

case $# in
(0)	echo 'No time value given for sleep.'
	exit 1;;
(1)	time=$1
	note="Timer is counting down to $time."
	break;;
(*)	time=$1
	shift
	note=$*;;
esac
echo "time is $time"
echo "note is $note"

If you don't see what it is doing try invoking your script with:

bash -xv scriptname
bash -xv scriptname 15
bash -xv scriptname 30 Note is one or more command line operands.

Thanks. How do I get this to show the double quotes ?

echo -e "   alarm.sh 1m "Take bread out of oven.""

Three of hundreds of possible ways:

echo -e "   alarm.sh 1m \"Take bread out of oven.\""
echo -e '   alarm.sh 1m "Take bread out of oven."'
echo -e "   alarm.sh 1m 'Take bread out of oven.'"

You can't use the second form if the string you want printed between the quotes is the expansion of a shell variable.

1 Like