Operating System - HP-UX
1751965 Members
4500 Online
108783 Solutions
New Discussion юеВ

Re: How to keep special meaning "*" inside a script

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor
Solution

Re: How to keep special meaning "*" inside a script

Hi (again):

Do you mean that you want to disable or enable globbing (file name generation). If so:

set -f

...disables shell file name generation.

set +f

...enables shell file name generation.

You can certainly choose the option you want inside a script to make it differ (or not) from your shell environent.

Regards!

...JRF...
Leif Halvarsson_2
Honored Contributor

Re: How to keep special meaning "*" inside a script

Hi,
You perhaps want to do something if there is any files. Try the following:

for file in `ls /tmp/ffin* 2>/dev/null`
do
echo $file
done
Mike Miller_8
Regular Advisor

Re: How to keep special meaning "*" inside a script

Hi,

Try the following :


if [ -f /tmp/ffin* ]; then
echo 'Found files'
fi

regards,

= Mike =
Jdamian
Respected Contributor

Re: How to keep special meaning "*" inside a script

I agree with James R. Ferguson.

If filename generation is active, shell will replace your original line when it is going to be executed:

if test -f /tmp/ffin*

for

if test -f /tmp/ffin02.txt /tmp/ffin09 /tmp/ffin.old

if there are filenames that match the pattern /tmp/ffin*

If not shell will keep the original line:

if test -f /tmp/ffin*

and test will check if /tmp/ffin* file exist (test will not expand the metacharacter *).

Thus, I think that, if file name generation is on, your script would run fine.
Manel Ventura
Advisor

Re: How to keep special meaning "*" inside a script

Thanks a lot, guys!
I wanted to enable file name generation. The problem was that I had the next parameter at the begin of the script:

#! /bin/sh -f

Next time, I'll send you the full script for detailed analysis ;-)