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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
03-11-2004, 01:02 PM
|
#1
|
LQ Newbie
Registered: Mar 2004
Posts: 1
Rep:
|
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.
|
|
|
03-12-2004, 08:41 AM
|
#2
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
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
|
|
|
02-22-2005, 05:54 AM
|
#3
|
LQ Newbie
Registered: Feb 2005
Location: germany
Distribution: Suse/sun/AIX
Posts: 3
Rep:
|
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
|
|
|
02-22-2005, 06:01 AM
|
#4
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
weird.
Yes it worked on solaris.
???
try quotes around "*.env" ?
|
|
|
02-22-2005, 06:08 AM
|
#5
|
LQ Newbie
Registered: Feb 2005
Location: germany
Distribution: Suse/sun/AIX
Posts: 3
Rep:
|
> 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 09:05 AM.
|
|
|
02-22-2005, 08:52 AM
|
#6
|
LQ Newbie
Registered: Feb 2005
Location: germany
Distribution: Suse/sun/AIX
Posts: 3
Rep:
|
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
|
|
|
All times are GMT -5. The time now is 03:45 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|