I am trying to run a python script with several arguments from bash. Some of the arguments are path names with asterisks as wildcards. However, I've been having some trouble passing the arguments into python. In attempt 1, the asterisk in ${config} got expanded by bash into a list of the files that matches the wildcard.
Attempt 1:
project_name="foo"
config="--G_ckpt /mnt/d/Documents/GAN/results/*_$name/${project_name}_g_param_epoch*.pkl --pattern */*.jpg"
python gan.py ${config}
In attempt 2, I quoted "${config}"
to prevent bash from expanding the variable. However, now python seems to see the whole "$config" as a single string.
Attempt 2:
project_name="foo"
config="--G_ckpt /mnt/d/Documents/GAN/results/*_$name/${project_name}_g_param_epoch*.pkl --pattern */*.jpg"
python gan.py "${config}"
Output from my python script (attempt 2):
print(sys.argv)
>> ['gan.py', '--G_ckpt /mnt/d/Documents/GAN/results/*_$name/${project_name}_g_param_epoch*.pkl --pattern */*.jpg']
One way around this is to break "$config"
into several variables eg. config0="--G_ckpt", config1="/mnt/d/Documents/GAN/results/*_$name/${project_name}_g_param_epoch*.pkl"
and then python gan.py $config0 "$config1"
.
However, this will make my script much more complicated. In my actual script I have several dozens of these asterisk arguments.
Does anyone know a simple solution to pass path names with asterisk from bash to python as arguments?