如何回应包含在bash的转义美元符号的变量 [英] How to echo a variable containing an unescaped dollar sign in bash

查看:354
本文介绍了如何回应包含在bash的转义美元符号的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有包含转义美元符号的变量,有什么办法,我可以附和变量的全部内容?

If I have a variable containing an unescaped dollar sign, is there any way I can echo the entire contents of the variable?

例如调用一些脚本:

./ script.sh测试1 $ test2的

,然后如果我想用它获得的参数截断,例如:

and then if I want to use the parameter it gets "truncated" like so:

回声$ {1}结果
测试1

当然单引号的varaible名于事无补。我无法弄清楚如何引用它,这样我至少可以躲避美元符号自己一旦脚本临危参数。

Of course single-quoting the varaible name doesn't help. I can't figure out how to quote it so that I can at least escape the dollar sign myself once the script recieves the parameter.

推荐答案

在运行脚本之前变量被替换。

The variable is replaced before the script is run.

./script.sh 'test1$test2'

这篇关于如何回应包含在bash的转义美元符号的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆