Operating System - HP-UX
1832058 Members
3239 Online
110034 Solutions
New Discussion

wildcard character inside of a variable

 
SOLVED
Go to solution
Jose Mosquera
Honored Contributor

wildcard character inside of a variable

Hi all,

I will try to simplify mi issue with a very simple example. I have the following files:
myfile.txt
otherfiles.txt
otherfiles.grp
otherfiles.ini
Then I have the following variable and "for" rutine:
INCLUDE="myfile.txt otherfiles*"
for FILE in $INCLUDE
do
echo "$FILE" >> list.out
done

I need that wild character will be keeped (do not expanded) in list.out file. I need have this list.out content:
myfile.txt
otherfiles*

Thanks in advance.
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: wildcard character inside of a variable

Hi:

If you want to disable the shell's file name generation (globbing), add:

set -f

...to your script.

#!/usr/bin/sh
set -f
INCLUDE="myfile.txt otherfiles*"
for FILE in $INCLUDE
do
echo "$FILE" >> list.out
done

Regards!

...JRF...
Jose Mosquera
Honored Contributor

Re: wildcard character inside of a variable

Ooopss, an small detail. Thank you very much for your sooner assistance!

Best rgds.
Jose Mosquera
Honored Contributor

Re: wildcard character inside of a variable

Thanks again. Works perfectly.