Register
It is currently Fri Jul 25, 2014 5:23 am

variables


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Mon Jun 08, 2009 12:50 am   

Joined: Mon Jun 08, 2009 12:28 am
Posts: 1
Hi, I'm new to bash scripting and programming. Just curious is there a better way of writing the below code? What I want to achieve is that if the variables is either 0 to 9 or Up or Down or Left or Right then it will run xdotool key $cmd1 and if its ok key it will run xdotool key "Control_L+Alt_L" and all others will run php /var/www/phpserial/sendSerial.php -c$cmd1 -v$cmd2. Thanks

Code:
case "$rcstate" in
1)
if [ $cmd1 == [0-9] ]; then
   xdotool key "$cmd1"
elif [ $cmd1 == Up ]; then
   xdotool key "$cmd1"
elif [ $cmd1 == Down ]; then
   xdotool key "$cmd1"
elif [ $cmd1 == Left ]; then
   xdotool key "$cmd1"
elif [ $cmd1 == Right ]; then
   xdotool key "$cmd1"
elif [ $cmd1 == ok ]; then
   xdotool key "Control_L+Alt_L"
else
   php /var/www/phpserial/sendSerial.php -c$cmd1 -v$cmd2
fi


Top
 Profile  
 PostPosted: Fri Jun 12, 2009 5:15 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
indeed case is used to avoid `if elif elif...fi` statements
Code:
case $cmd1 in
[0-9]) do_comand
;;
up) do_other_hing
;;
# and so on
esac
more or less


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP