[英]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. 但是,$ 1和$ 2并没有被我传递的两个参数所替代。 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 直接执行,将$ 1和$ 2替换为正确的用户名和密码即可正常工作
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. 请参阅下面的glenn评论。 The quotes prevented special characters in the password from being interpreted.
引号防止解释密码中的特殊字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.