Register
It is currently Mon Oct 20, 2014 3:37 am

using case to check for arguments...


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Nov 19, 2006 6:49 am   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
Code:
#!/bin/bash
var0="`ls`"
var1="$1"
var2="$2"
case "$var1" in
        -e      )  echo "$var2";;
        --echo  )  echo "$var2";;
        -f      )  echo "$var0";;
        --file  )  echo "$var0";;
        *       )  echo "please supply a valid option";;
esac

At first i tried to do this with if/elif but it just wasn't working so i googled using case as i never really knew how to use it - so this is a first for me and uisng case will come in useful i feel :).


Top
 Profile WWW  
 PostPosted: Mon Nov 20, 2006 8:14 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
crudball wrote:
Code:
#!/bin/bash
var0="`ls`"
var1="$1"
var2="$2"
case "$var1" in
        -e      )  echo "$var2";;
        --echo  )  echo "$var2";;
        -f      )  echo "$var0";;
        --file  )  echo "$var0";;
        *       )  echo "please supply a valid option";;
esac

At first i tried to do this with if/elif but it just wasn't working so i googled using case as i never really knew how to use it - so this is a first for me and uisng case will come in useful i feel :).


you can actually make that a little easier too...
Code:
#!/bin/bash
var0="`ls`"
var1="$1"
var2="$2"
case "$var1" in
        -e | --echo )  echo "$var2";;
        -f  | --file    )  echo "$var0";;
        *    )  echo "please supply a valid option";;
esac


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 8 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:  
cron


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