matejak / argbash

Bash argument parsing code generator
Other
1.39k stars 63 forks source link

ARG_LEFTOVERS functionality dependent on bash version #161

Closed gdevenyi closed 2 years ago

gdevenyi commented 2 years ago

I have the following argbash configuration:

#!/bin/bash

# Created by argbash-init v2.10.0
# ARG_HELP([DBM post-processing for twolevel_modelbuild.sh from optimized_antsMultivariateTemplateConstruction])
# ARG_OPTIONAL_SINGLE([output-dir],[],[Output directory for modelbuild],[output])
# ARG_OPTIONAL_SINGLE([jacobian-smooth],[],[Comma separated list of smoothing gaussian FWHM, append "vox" for voxels, "mm" for millimeters],[4vox])
# ARG_OPTIONAL_SINGLE([walltime],[],[Walltime for short running stages (averaging, resampling)],[00:15:00])
# ARG_OPTIONAL_BOOLEAN([debug],[],[Debug mode, print all commands to stdout],[])
# ARG_OPTIONAL_BOOLEAN([dry-run],[],[Dry run, don't run any commands, implies debug],[])
# ARG_POSITIONAL_SINGLE([inputs],[Input text files, one line per subject, comma separated scans per subject],[])
# ARG_LEFTOVERS([Arguments to be passed to dbm.sh without validation])
# ARGBASH_SET_INDENT([  ])
# ARGBASH_GO()

On my local (development) system,

$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)

On the production system:

$ bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

On my development system, I can do

> ./script.sh inputs.csv
<THINGS FUNCTION AS NORMAL>

Whereas on the production system:

> ./script.sh inputs.csv
script.sh: line 187: _arg_leftovers[@]: unbound variable

Somehow, the lack of leftovers has resulted in the variable not being set, or being unset after its default initialization.

gdevenyi commented 2 years ago

Turns out not a bug with argbash, instead earlier versions of bash will error out with set -u and trying to expand empty arrays.

Solution was: ${_arg_leftovers[@]+"${_arg_leftovers[@]}"}