[英]read[command] in bash
When I read[command] some lines including character '*'
, it seems that '*'
will be looked as a wildcard. 当我阅读[命令]某些包含字符'*'
,似乎'*'
将被视为通配符。 whether exsits some solutions leting '*'
just be a '*'
, please! 是否exsits一些解决方案乐亭'*'
只是一个'*'
,请!
It depends how you use the variable: if you quote it, filename expansion will not happen. 这取决于变量的使用方式:如果引用该变量,则不会扩展文件名。 Example: 例:
$ ls
f1 f2 f3
$ read line
*
$ echo "$line"
*
$ echo $line
f1 f2 f3
You can escape it with the escape character: \\*
. 您可以使用转义字符\\*
对其进行转义。 This means the *
will be a literal *
, not matching one or more characters as the glob pattern. 这意味着*
将是文字*
,不匹配一个或多个字符作为全局模式。
If you do not want any of the special file name characters to be used as wildcards then enter the following in your script before the read. 如果您不希望将任何特殊文件名字符用作通配符,则在读取之前在脚本中输入以下内容。
set -o noglob
This will prevent the * ? 这样可以防止*? and [] from having special meaning and treat them as normal characters. 和[]具有特殊含义,并将其视为普通字符。
The following example demonstrates the point 以下示例说明了这一点
touch 1 2 3
echo "With wild card expansion"
echo *
echo "Without wild card expansion"
set -o noglob
echo *
And produces the following results With wild card expansion 1 2 3 Without wild card expansion *
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.