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?

Allen W
  • 31

1 Answers1

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