Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

escape * 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL
hello,
is it feasible to pass "*" as the parameter into script?
here is my example where * delivers file names from current directory:

Code:
$ ls
dir1  file1  file2  test
$ cat test
#!/bin/bash

echo $@

set $(echo $@)

echo 1:"$1" 2:"$2" 3:"$3" 4:"$4" 5:"$5"
$ ./test 1 2 3 4 5
1 2 3 4 5
1:1 2:2 3:3 4:4 5:5
$ ./test 1 2 * 4 5
1 2 dir1 file1 file2 test 4 5
1:1 2:2 3:dir1 4:file1 5:file2
$
 
ok, I have some result using:
#!/bin/bash -f

$ ./test 1 2 \* 4 5
1 2 * 4 5
1:1 2:2 3:* 4:4 5:5
 
Your shell will always expand an asterisk to all file names in the current directory, unless you escape it, protect it, or turn it off. That is, the backslash like you found, embedded it in single quotes, or just turn off wildcard expansion.

Code:
$ # escape it
$ echo \*
*
$ # protect it
$ echo '*'
*
$ # turn it off
$ set noglob
$ echo *
*
$ # another way to turn it off
$ set -f
$ echo *
*
$



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top