LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-11-2004, 12:02 PM   #1
r18044
LQ Newbie
 
Registered: Mar 2004
Posts: 1

Rep: Reputation: 0
ksh check if file exists (using wildcard) problem


Within my ksh script I am executing the following:

if [ -f *.pnr.* ]
then
.....
fi

if there exists one and only one file that satisifies this condition, the script runs successfully.

if there exists more than one file that satisifies this condition, I receive the following message:

./pnr.ksh[190]: [: /home/pnr/2004.03.10.1000.pnr.ready: unexpected operator/operand

The files that exist in the sub-directory include:

/home/pnr/2004.03.10.1000.pnr.file1
/home/pnr/2004.03.10.1000.pnr.ready

This script works on a solaris box but I'm not sure why it does not work on linux.

Any help is appreciated.

Thanks.
 
Old 03-12-2004, 07:41 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
hmm. remember it's usually pdksh on linux rather than the full blown one.
perhaps the 'test' is a bit different on linux.

do:

Code:
echo "*.pnr.*
if [ -f *.pnr.* ]
then
.....
fi
so we can see what the test is evaluating.



billy
 
Old 02-22-2005, 04:54 AM   #3
sanojca
LQ Newbie
 
Registered: Feb 2005
Location: germany
Distribution: Suse/sun/AIX
Posts: 3

Rep: Reputation: 0
Post

I've the same problem under Suse Linux Enterprise Server 8 for a script which works on sun.

> echo "*.env"
*.env
> if [ -f *.env ]
2> then
2> echo ja
2> fi
ksh: [: APPSORA.env: unexpected operator/operand

By the way the filename APPSORA.env one file matching to the pattern *.env.

What is wrong with that code which run under sun solaris?

Werner
 
Old 02-22-2005, 05:01 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
weird.
Yes it worked on solaris.

???
try quotes around "*.env" ?
 
Old 02-22-2005, 05:08 AM   #5
sanojca
LQ Newbie
 
Registered: Feb 2005
Location: germany
Distribution: Suse/sun/AIX
Posts: 3

Rep: Reputation: 0
> if [ -f "*.env" ]
2> then
2> echo yes
2> else
2> echo no
2> fi
no

I tried with quotes. Then it echos "no" even though there exists file in the directory.

Werner

Last edited by sanojca; 02-22-2005 at 08:05 AM.
 
Old 02-22-2005, 07:52 AM   #6
sanojca
LQ Newbie
 
Registered: Feb 2005
Location: germany
Distribution: Suse/sun/AIX
Posts: 3

Rep: Reputation: 0
For my actual migrated code I quit using test operator with wildcards (unless someone has an idea or explanation). I use the workaround:

if (ls *.env >/dev/null)
then
..
fi

Werner
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SIOCADDRT: File exists SIOCCADDRT: File Exists Failed to bring up eth0. opsraja Linux - Networking 0 01-10-2005 08:29 AM
Linker problem: can't find a file, but the file exists atlep Programming 5 08-16-2004 06:15 AM
c++ check if file exists Genjix Programming 3 03-15-2004 12:08 AM
how to find file using wildcard? huangyanfeng Linux - General 3 10-15-2003 09:21 PM
Subdomais Apache *wildcard CNAME - VirtualDocumentRoot - config file Rai Paul Linux - General 4 06-01-2003 08:19 PM


All times are GMT -5. The time now is 01:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration