0

I am new to shell script and I had the following situation. I have a perl script that has multiple options. Not all the options are required.

example.prl [options]
options: 
    -h             help
    -o filename    output file name
    -f             force output file overwrite
    -d             debug mode
    ...

I want to create a shell script to parse the options to the prl script. And the options are not all required, for instance:

./example.sh -o output_file 
OR
./example.sh -o output_file -f

Here is some of my progress but only work with 1 argument:

#!/bin/bash

path=/proj/scripts/example.prl
option=$1
option_value=$2

echo "The command to run:"
echo $path $name $option 
$path $option $option_value 

Is there a way to loop through all of the options user put and construct the command?

marked as duplicate by Ipor Sircer, Community Dec 18 '17 at 19:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0
#!/bin/bash
while [[ ! -z "$1" ]]; do
    case "$1" in
        -a)
            handle_dasha
            ;;
        -b)
            and_so_on
            ;;
    esac
    shift
done

Not the answer you're looking for? Browse other questions tagged or ask your own question.