Skip to main content
deleted 3 characters in body
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately. In this configuration the quoted patterns are then handled by the shell (and therefore by getopts) as only one argument each.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift `expr$(( "$OPTIND"OPTIND - 1`1 )) # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./multitool -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana acherry) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately. In this configuration the quoted patterns are then handled by the shell (and therefore by getopts) as only one argument each.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift `expr "$OPTIND" - 1` # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./multitool -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana acherry) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately. In this configuration the quoted patterns are then handled by the shell (and therefore by getopts) as only one argument each.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift $(( OPTIND - 1 )) # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./multitool -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana acherry) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 
added 128 characters in body
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately. In this configuration the quoted patterns are then handled by the shell (and therefore by getopts) as only one argument each.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift `expr "$OPTIND" - 1` # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./multitool -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana acherry) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift `expr "$OPTIND" - 1` # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./multitool -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana acherry) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately. In this configuration the quoted patterns are then handled by the shell (and therefore by getopts) as only one argument each.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift `expr "$OPTIND" - 1` # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./multitool -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana acherry) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 
Tidying up
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool.sh -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift `expr "$OPTIND" - 1` # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./ma.shmultitool -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana acherry) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool.sh -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift `expr "$OPTIND" - 1` # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./ma.sh -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 

If you're happy to copy the approach used by find and quote the two wildcard glob patterns you can use your script to expand the values appropriately.

Here's an example, where I've taken your existing code pretty much unchanged and shrunk it for (my) convenience. Your code is laid out better, but the interesting parts are the processing of the -a and -b arguments:

#!/bin/bash # # Multiple arguments: multitool -hp -a 'a*.txt' -b 'b*.txt' # ######################################################################## # while getopts ':hpg:a:b:' option do case "$option" in a) a_list=($OPTARG) ;; # Expand the (quoted) argument to the a_list array b) b_list=($OPTARG) ;; # Expand the (quoted) argument to the b_list array h) echo "HELP!" >&2; exit 1 ;; p) l_peaks="$OPTARG" ;; g) l_bgraphs="$OPTARG" ;; \?) echo "ERROR!" >&2; exit 1 ;; esac done shift `expr "$OPTIND" - 1` # Checking values # echo "l_peaks=$l_peaks, l_bgraphs=$l_bgraphs" echo "a_list=(${a_list[@]})" echo "b_list=(${b_list[@]})" echo for ((i=0; i<="${#a_list[@]}"; i++)) do printf '%d\t%s\t%s\n' "$i" "${a_list[$i]}" "${b_list[$i]}" done 

Example

ls aapple abanana acherry bone bthree btwo ./multitool -p -a 'a*' -b 'b*' l_peaks=, l_bgraphs= a_list=(aapple abanana acherry) b_list=(bone bthree btwo) 0 aapple bone 1 abanana bthree 2 acherry btwo 
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324
Loading