Let's say I have a script which echoes $1
#!/bin/bash
echo $1
It's called test.sh
.
Then I call /bin/test.sh 'test'
. The output is test
. But this doesn't work:
/bin/test.sh 'te'st'
There's a syntax error.
There can be anything between those two single quotes, e.g.
/bin/test.sh 'te"s"t'` or `/bin/test.sh 'te's't'` or `/bin/test.sh 'te"s't'
Is there a way to deal with this? I can work only with enclosing quotes. I can't alter what is inside the variable; it's a log parsing. Anything can be inside a log entry.
I need for bash to take those arguments correctly.
Example:
/bin/test.sh '2015.11.11 07:45:44.060|executor-2|||ERROR|236 - PDF document for 5616904 wasn't created!'
This doesn't work because of the single '
in the word wasn't inside the string.
The string is beeing placed exactly as I wrote it. I am using it with Zabbix (monitoring solution). So in zabbix it's something like this:
/bin/test.sh '{$TRIGGER.VALUE}'
But in the end {$TRIGGER.VALUE}
is replaced with the actual string and script is called with literal value.
te'st
contained in a shell variable or is it a literal? – iruvar Nov 18 '15 at 13:01This doesn't work becouse of single ' in word wasn't inside the string
– Pepa Vidlák Nov 18 '15 at 13:102015.11.11 07:45:44.060|executor-2|||ERROR|236 - PDF document for 5616904 wasn't created!
being placed ontest.sh
's command line? Via a variable, command substitution or something else? – iruvar Nov 18 '15 at 13:13I'am using it with Zabbix (monitoring solution)
So in zabbix its something like this: /bin/test.sh '{$TRIGGER.VALUE}' But in the end {$TRIGGER.VALUE} is replaced with the actual string and script is called with literal value.
– Pepa Vidlák Nov 18 '15 at 13:21