[英]command substitution in shell script with shell variables within the substitution
[英]Parameter substitution within shell script when executing another command
我写了一个脚本,可以卷曲和下载数据库
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
但是,$ 1和$ 2并没有被我传递的两个参数所替代。 我该怎么做? 我尝试了多种替代方法,但仍然没有成功。
直接执行,将$ 1和$ 2替换为正确的用户名和密码即可正常工作
为了回答我自己的问题,这可行:
DB_URL=$(curl --user "$1":"$2" -s https://myurl.com/ | grep -o \\http\\:[a-zA-Z.0-9\\:/-]* | grep DBNAME$ | tail -1)
必须将变量放在引号中。
请参阅下面的glenn评论。 引号防止解释密码中的特殊字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.