我怎样才能传递特殊字符[例如。 "或(或']作为shell脚本的参数?

时间:2012-08-25 13:13:42

标签: bash shell command-line-arguments

在将参数传递给outlook_DataParsing.sh时出现了一个错误:

$ sh outlook_DataParsing.sh delete node doc('/opt/ws40/contacts.xml')//Directory/Contacts/Contact[@id='22222']

我正在阅读所有论点:

str=$@

错误如下:

-bash: syntax error near unexpected token `('

有人能帮助我吗?

1 个答案:

答案 0 :(得分:5)

shell命令中有许多“特殊”字符,包括$()[]

大多数这些都可以简单地通过将参数括在双引号

中来传递
foo "(hello)[]"

然而,这不会修复$符号,因为它适用于变量。您可以改为使用单引号传递$ sign

foo '$im_not_a_variable'

如果所有其他方法都失败了,任何字符都可以使用反斜杠转义\包括空格(不需要引号)

foo \(hello\)\[\]\ \$im_not_a_variable