Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Question
In linux, write simple bash script, using case statement to check for first command line argument, if it is --help or -h print "help", if it is --version or -v print "1.0", otherwise print "unkown choice".
Answer
case $1 in
    --help|-h)
        echo "help"
        ;;
    --version|-v)
        echo "1.0"
        ;;
    *)
        echo "unknown choice"
        ;;
esac
^^ note the esac at end
^^ note the ;; seperating each option statement
^^ note the ) that is each pattern matching condition, also note that the left ( is missing/optional
^^ note the * catch all glob/pattern for the final condition

Question
In linux, write simple bash script, using case statement to check for first command line argument, if it is --help or -h print "help", if it is --version or -v print "1.0", otherwise print "unkown choice".
Answer
?

Question
In linux, write simple bash script, using case statement to check for first command line argument, if it is --help or -h print "help", if it is --version or -v print "1.0", otherwise print "unkown choice".
Answer
case $1 in
    --help|-h)
        echo "help"
        ;;
    --version|-v)
        echo "1.0"
        ;;
    *)
        echo "unknown choice"
        ;;
esac
^^ note the esac at end
^^ note the ;; seperating each option statement
^^ note the ) that is each pattern matching condition, also note that the left ( is missing/optional
^^ note the * catch all glob/pattern for the final condition
If you want to change selection, open document below and click on "Move attachment"

7. Shell Scripting
ng files and expand an absolute path. 7.6 The case Statement The case statement can make a potentially complicated program very short. It is best explained with an example. 5 10 15 20 #!/bin/sh <span>case $1 in --test|-t) echo "you used the --test option" exit 0 ;; --help|-h) echo "Usage:" echo " myprog.sh [--test|--help|--version]" exit 0 ;; --version|-v) echo "myprog.sh version 0.0.1" exit 0 ;; -*) echo "No such option $1" echo "Usage:" echo " myprog.sh [--test|--help|--version]" exit 1 ;; esac echo "You typed \"$1\" on the command-line" Above you can see that we are trying to process the first argument to a program. It can be one of several options, so using if statements wil

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.