user3632739
user3632739

Reputation: 19

bash getopts options for different functions

how can I make this work? I want to use different functions for my command, my problem is how can I pass arguments to the add.sh function? find.sh works fine but the first two commands says no arg for -v / -a option. What am I doing wrong?

while getopts v:a:s opt
do
case "$opt" in

v) ./view.sh;;

a) ./add.sh;;

s) ./find.sh;;

Upvotes: 0

Views: 141

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 753555

If you want to pass the -v option onto the view.sh script, then do so:

while getopts v:a:s opt
do
    case "$opt" in
    v) ./view.sh -v "$OPTARG";;
    a) ./add.sh -a "$OPTARG";;
    s) ./find.sh;;
    esac
done

If you want to pass the 'other' arguments to view.sh too, then you have to work a bit harder. You could simply pass all the arguments with ./view.sh "$@";; but being selective is harder.

Upvotes: 1

Related Questions