I am working on the raspberry pi (Raspberry Pi OS):
I run a Bash #!/bin/bash
script where I need to save a file (a picture that is taken) under a directory which has spaces in its name.
In my case the directory is: /media/pi/test 1 2 3
And the command I run and does what I want:
raspistill -awb greyworld -vf -hf -o /media/pi/"test 1 2 3"/test.jpg
Which takes a picture and saves it there, works fine.
My issue is, I want the "test 1 2 3" to be inside a variable, like this:
usbToSave="\"test 1 2 3\"" #usbToSave is now "test 1 2 3"
raspistill -awb greyworld -vf -hf -o /media/pi/$usbToSave/test.jpg
But the above will throw me this error:
Invalid command line option (1)
Which I do not understand why. I am sure something like this has already been answered somewhere in the forum, but I cannot find it. I guess I don't use the right keywords to search for it.
Note:
If, my directory has no spaces for example /media/pi/test
the Bash script:
usbToSave="test"
raspistill -awb greyworld -vf -hf -o /media/pi/$usbToSave/test.jpg
Works with no errors.
usbToSave
would have worked. But it doesn't. In the same way as shell operators or other expansions from the results of a variable expansion don't work. Which is actually exactly the opposite of how I recall macro processors working, the ones I know about anyway. – ilkkachu Mar 22 '21 at 10:35