Let's say I have a script which echoes $1#!/bin/bashecho $1It'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 'test'` or `/bin/test.sh 'te's't'` or `/bin/test.sh 'tes'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.
How to escape single or double quotes when passing a variable to bash script?
bash;shell;quoting;string