简体   繁体   中英

Parameter substitution within shell script when executing another command

I have written a script which curls and downloads a DB

DB_URL="$(curl --user $1:$2 -s https://myurl.com/ | grep -o \\http\\:[a-zA-Z.0-9\\:/-]* | grep DBNAME$ | tail -1)"

echo -e "\\033[33;31m The database is here :" echo $DB_URL

But, the $1 and $2 are not being substituted with the two params that I am passing. How do I do it? I have tried many different ways to substitute but still no success.

Works fine when executed directly by replacing $1 and $2 with correct username and password

To answer my own question, this worked :

DB_URL=$(curl --user "$1":"$2" -s https://myurl.com/ | grep -o \\http\\:[a-zA-Z.0-9\\:/-]* | grep DBNAME$ | tail -1)

Had to put the variables in quotes.

See glenn's comment below. The quotes prevented special characters in the password from being interpreted.

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