相关疑难解决方法(0)

在Bash中的命令中扩展变量在单引号内

我想从一个bash shell脚本运行一个命令,该脚本在单引号和变量中有单引号和一些其他命令.

例如 repo forall -c '....$variable'

在此格式中,$进行转义并且不扩展变量.

我尝试了以下变化,但他们被拒绝了:

repo forall -c '...."$variable" '

repo forall -c " '....$variable' "

" repo forall -c '....$variable' "

repo forall -c "'" ....$variable "'"
Run Code Online (Sandbox Code Playgroud)

如果我用值代替变量来执行命令就好了.

请告诉我哪里出错了.

variables bash shell quotes

344
推荐指数
3
解决办法
31万
查看次数

在CURL中扩展变量

以下curl语句在我的shell脚本中正常工作.

curl -Ld'username=user&password=password&source=oksoft&dmobile='$mnumber'&message=Slave is working OK' http://167.123.129.195/smsclient//api.php
Run Code Online (Sandbox Code Playgroud)

手机号码按预期扩展.但是当我使用变量作为message参数时,我得到$ myvar输出而不是扩展变量.

curl -Ld'username=user&password=password&source=oksoft&dmobile='$mnumber'&message="$myvar"' http://167.123.129.195/smsclient//api.php
Run Code Online (Sandbox Code Playgroud)

如何将该变量用于消息?

shell curl

3
推荐指数
1
解决办法
7382
查看次数

标签 统计

shell ×2

bash ×1

curl ×1

quotes ×1

variables ×1