I wrote a little script that check something, and i want a command to be executed from within the script if the test was successfull. And i don’t want to hardcode the command, but give it as argument to it like a callback script.
The command I testing with is /usr/bin/xmessage -buttons "button a","button b" some text to test. Running it within a terminal standalone works fine, no quotation marks needed for the last text.
The script looks like this:
#!/bin/bash
echo "$1"
$1
But when running /path/to/script.bash '/usr/bin/xmessage -buttons "button a","button b" some text to test' it looks like this, though the echo looks right.
When using "$1" instead of $1 it complains it couldn’t find the file. Anyone got ideas how to fix the behavior with the space?
I suggest you write the script like this:
And call it like this: