简体   繁体   中英

Escape special characters in a bash script

I have a command that I want to put in a script but I'm having issues. The command is very picky and it looks like this:

command_to_run -H 'ip_address' -u 'user' -p 'passwd' --register naming_data "/location/of/backup/folder/" "[destination-location]"

I want to create an interactive bash script that asks the user for the ip_address, user, password, location of backup folder and a destination location. The problem I'm having is that I'm storing the user's input on variables (IP_ADD, USERNAME, etc) but when I pass it to the command like

$COMMAND -H '$IPADD' -u '$USERNAME' .....

but again my issues are in the single quotes, the "/" the "[]" ad passing the variables. Can anyone give me a hint and what I need to fix in order to have it working??

就像Etan所说的那样,使用双引号:

command_to_run -H "$ip_address" -u "$user" -p "$passwd" ....

Use double quotes:

$COMMAND -H "$IPADD" -u "$USERNAME" ...

If you use single quotes in the shell, variables will not getting expanded meaning the literal $USERNAME will being used for the username.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM