-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexemple.sh
More file actions
executable file
·32 lines (24 loc) · 1.42 KB
/
Copy pathexemple.sh
File metadata and controls
executable file
·32 lines (24 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# Try this programm:
# $ ./exemple.sh
# $ ./exemple.sh --help
# $ ./exemple.sh --verbose --config toto
# $ ./exemple.sh --config toto my_out_file.txt my_in_file.tab
# You can use options and positionals arguments anywhere.
# $ ./exemple.sh my_out_file.txt my_in_file.tab --config toto my_other_in_file
source paramparser.sh
## Exemple:
## Create your arguments:
optAdd 'config' 'CONFIG_FILE' 'Input config file' '?' ':NO_CONFIG:' # Add an option which requires an argument. This line create 'config' variable initialised at ':NO_CONFIG:'.
optAdd 'col' 'NUM_COLUMN' 'Display this column' '*' # Add an option which requires an argument. '*' means that an array named 'col' will be created instead of a simple variable.
optAddFlag 'verbose' 'Displays more descriptive information than the default output.' # Add a flag option. This line create boolean 'verbose' variable.
optAddPos 'output_file' 'Tabular file with first column is an id' # Add a positional argument.
optAddPos 'input_file' 'Path to output file' '+' # Add an other positional argument '+' means create 'output_file' array and store the last positionals arguments.
# Use optParse function to parse users argument.
optParse "$@"
# Display user value
echo 'config :' $config
echo 'col :' ${col[@]}
echo 'verbose :' $verbose
echo 'positional argument 1 :' $output_file
echo 'last positionals arguments :' "${input_file[@]}"