如何在Bash变量名称中使用`-`? [英] How to use `-` in the name of a Bash variable?
问题描述
我存储了一个名为 jenkins-vm ="Jenkins"
的变量,同时使用 echo $ jenkins-vm
调用了该变量我面临错误.在变量中使用-"时如何转义?
I stored a variable named jenkins-vm="Jenkins"
while calling the variable using echo $jenkins-vm
I am facing error.
How can I escape "-" while using it in a variable?
推荐答案
在Bash shell的变量名中不允许使用连字符或破折号-
.仅支持小写/大写 ASCII 字母、_
(下划线)和数字,且首字符不得为数字.用下划线字符替换变量名称中的连字符将起作用,并且变量名称仍将易于阅读.
The hyphen or dash character -
is not allowed in a variable name in the Bash shell. Only lowercase/uppercase ASCII letters , _
(underline), and digits are supported, and the first character must not be a digit. Replacing the hyphen(s) in the variable name with underline characters will work, and the variable name will still be easy to read.
这篇关于如何在Bash变量名称中使用`-`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!