简体   繁体   English

bash脚本:var =“[| -d]”

[英]bash script: var=“[|-d]”

I found it weird that my program started to output some "b's" that I did not type. 我发现我的程序开始输出一些我没有输入的“b”,这很奇怪。 Then I found out this: 然后我发现了这个:

var="[|-a]"
echo $var
var="[|-b]"
echo $var
var="[|-c]"
echo $var
.
.
.

The first echo outputs what I intend: [|-a]. 第一个echo输出我的意图:[| -a]。 The others, from b to z, always output "b". 其他的,从b到z,总是输出“b”。 Why? 为什么?

You forgot to quote the variable on output, and you have a file called "b" that the character range expression is matching. 您忘记在输出中引用变量,并且您有一个名为“b”的文件,字符范围表达式匹配。

var="[|-a]"
echo "$var"
var="[|-b]"
echo "$var"
var="[|-c]"
echo "$var"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM