I'm making a wrapper script for a command in bash and I want to pass string arguments with whitespace while keeping it as a string inside the bash file.
I've seen many questions which refer to passing a string as one item to a bash script, but not how to maintain the string should the intention be for it to remain as a string when being usedin the script.
I've also tried numerous different ways of quoting and escaping characters to see if it makes any difference
An example of how my script is laid out is
#!/usr/bin/env bash
exec my_program /path/to/code.py "${@}"
When I execute my_script -arg "A string"
, the desired behaviour is to have the wrapped command to execute as my_program /path/to/code.py -arg "A string"
but instead it runs as my_program /path/to/code.py -arg A string
resulting in error: unrecognized arguments: string
.
Is there some way that I can ensure that, when passed a string, it will maintain the string all the way down?
A Minimal, Complete, and Verifiable example:
bash_strings.sh
echo "${@}"
Output
$ bash bash_strings.sh --test "A String"
--test A String