Prevent * extension in bash script

Linux bash script:

#!/bin/bash function Print() { echo $1 } var="*" Print $var 

Execution Results:

 alex@alex-linux :~/tmp$ ./sample-script sample-script 

* expands to a list of files, which is actually a script. How can I prevent this and see the actual value of the variable? In general, var can be more complicated than * , for example: home/alex/mydir/* .

+1
source share
2 answers

you also need to avoid your variables:

 Print "$var" 

And in your function:

 echo "$1" 
+5
source

set -o noglob

stop bash from expanding * and can be removed with "unset noglob"

+3
source

All Articles