This is because *
gets expanded as all files in your current directory.
You can avoid it with two ways:
As you said, by quoting, which makes shell interpret it as a string and not a parameter:
while read line do name=$line echo "$name" <---- echo within quotes done < definition.txt
Deactivating
noglob
: How do I disable pathname expansion in bash?.$ echo * one_file one_dir whatever $ set -o noglob <--- disable $ echo * * $ set +o noglob <--- enable again $ echo * one_file one_dir whatever
Quoting from man bash
:
The special pattern characters have the following meanings:
- Matches any string, including the null string. When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories.