Cannot Pass Whitespace Containing Shell Arguments - Double Quotes, Escape Chars etc. Not Working

40 Views Asked by At

Good Day StackOverflowers,

I am kicking off a Python3 script from a ZSH shell (Mac), but I cannot stop the arguments, which contain whitespace, from being interpreted as separate arguments. I.e. the argument "stack question" is interpreted as two arguments - "stack" and "question".

I have surrounded these arguments with double quotes. I have inserted \ before spaces. I have tried wrapping in {}. I have tried putting my "" inside a set of ''. I think this is happening because I am using a bash script to create the args, and they are being passed to python after being interpreted. I'm not calling the python3 execution directly, I am calling a bash script which then constructs the arguments and then calls the Python3 for me.

PATH="/Users/fishbones78/miniconda3/bin/":"/Users/fishbones78/miniconda3/cron_env/bin/":"/usr/local/bin":"/usr/bin":"/bin":"/user/sbin"

source /Users/fishbones78/miniconda3/etc/profile.d/conda.sh
conda activate cron_env

IN_DIR="/Users/fishbones78/Raw/"

FP=$(ls -t "${IN_DIR}/reportname"* | head -1)  <---- This is just grabbing the most recent file before passing the path as an argument

sudo -u fishbones78 python3 "[MY PYTHON SCRIPT]" $FP

I have checked the value of $FP using echo before the script is called, and even if it echoes with "" around the string, it ends up in Python as a load of separated args, still.

Many thanks in advance for any responses.

0

There are 0 best solutions below