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!
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 *
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.