Operating System - HP-UX
1752772 Members
4883 Online
108789 Solutions
New Discussion юеВ

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

 
SOLVED
Go to solution
Manel Ventura
Advisor

How to keep special meaning "*" inside a script

Hello,

I want to execute the following command inside a script but it doesn't work because the special character "*" lose its special meaning inside a script.

...
if test -f /tmp/ffin*
...

Has anyone any idea?
14 REPLIES 14
James R. Ferguson
Acclaimed Contributor

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

Hi:

Escape the asterisk with a backslash:

# touch /tmp/my\*file
# rm /tmp/my\*file

...are examples of this.

# if test -f /tmp/ffin\*

...would test for the presence of a file named '/tmp/ffin*'

Regards!

...JRF...
John Meissner
Esteemed Contributor

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

you could do it like this

if [ -f "/tmp/ffin*"]
then.....
All paths lead to destiny
Helen French
Honored Contributor

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

Use backslash (\) in front of * like this:

..../tmp/ffin\* ...
Life is a promise, fulfill it!
Manel Ventura
Advisor

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

Hello again,

I just want to keep the meaning of "*".

I want to know if there are files with the pattern "ffin". For example, ffin0202.txt or ffin0304.txt, ...
Ravi_8
Honored Contributor

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


Hi,

\* will keep metacharacter"*" anywhere
never give up
Leif Halvarsson_2
Honored Contributor

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

Hi,
Another way is to use single quotes.

# touch '/tmp/my*file'
# rm '/tmp/my*file'


Dario_1
Trusted Contributor

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

Hi!!

Use the backslash (\) before the *.

Regards,

DR
Francisco J. Soler
Honored Contributor

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

Hi, Manel

I resolved a similar question in
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xfc075ec05a7ad711abdc0090277a778c,00.html

try this:

if (ls /tmp/ffin* > /dev/null 2>&1) ; then echo Hi ; fi

Saludos
Frank.

Linux?. Yes, of course.
S.K. Chan
Honored Contributor

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

I don't think it allows multiple file test. One other way is this ..
..
if (($(ls /tmp/ffin*|wc -l) > 1))
...