Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Calling .sh(shell script) with the required parameters as below :-

sh home/example.sh --context_param dbUserName=username --context_param dbPassword=exam!ple##### --context_param resultDate=2017-01-13

calling example.sh with paramters dbUsername and password but getting following error:-

-bash: !ple#####: event not found

I think special characters restrict the command to execute. Then how i have to pass the special characters. Any help will be appreciable.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
645 views
Welcome To Ask or Share your Answers For Others

1 Answer

Change the line,

dbPassword=exam!ple#####

to,

dbPassword='exam!ple#####'

to avoid ! (history-expansion) being treated specially in bash

From man bash under QUOTING sub-section,

When the command history expansion facilities are being used (see HISTORY EXPANSION below), the history expansion character, usually !, must be quoted to prevent history expansion.

more under HISTORY EXPANSION

History expansions are introduced by the appearance of the history expansion character, which is ! by default. Only backslash () and single quotes can quote the history expansion character.

Also, it is a good practice to quote all your name-value pairs to prevent Word-splitting done by shell.

sh home/example.sh --context_param dbUserName="username" --context_param dbPassword='exam!ple#####' --context_param resultDate="2017-01-13"

About word-splitting, from the man page,

Word Splitting

The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting. The shell treats each character of IFS as a delimiter, and splits the results of the other expansions into words using these characters as field terminators


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...