I need to run a Bash command with a script calling parameters: comm1 ./script.sh param1 param2 param3.
Script includes this: timeout 10 bash -c " comm2 ./param1.param3". It indicates that param1 file is in the current directory.
And it works as long as param1 is a single word. But I need it to be a file name which can have spaces.
So command should be: comm1 ./script.sh "param1\ with\ space" param2 param3 . No dot and extension in file name, just spaces are problem and maybe brackets.
I don't know how to modify param1 to be able to use spaces in this case, and if script should also be modified. Thanks for help.
printf -v cmd_line '%q ' comm2 "$1" "$2"will generate a$cmd_linethat's correctly quoted with spaces from$1or$2escaped. Thereafter, you can runtimeout 10 bash -c "$cmd_line"bashat all, instead oftimeout 10 comm2 "$1" "$2"-- when you don't wrap things inbash -cyou don't need the extra escaping in the first place.comm2 ./param1 param2really ispre-comm2-param comm2 ./param1 param2meaning command has a special parameter before, so it didn't work all without bash -c.