LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-22-2012, 09:58 PM   #1
budgie26
LQ Newbie
 
Registered: Nov 2012
Posts: 17

Rep: Reputation: Disabled
Post If statements with multiple arguments and wildcards


I've been trying to update an existing script that has been written in csh, but cannot work out how to get an if statement to work with multiple arguments.

What I want to do is:

if 2 files exist in a single directory then run script_1, otherwise run script_2

The code I have is:

if (-e $dir/path/image-a-*) & (-e $dir/path/image-ab-*) then
script_1.pl
else
script_2.pl
else
echo "no files found"
exit
endif

I need to use wildcards for the file names because only the beginning of the name is the same.
 
Old 11-23-2012, 01:26 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,877

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
A few minutes of google searching for csh script examples suggest the if statement (with multiple arguments) should be written:
Code:
if (-e $dir/path/image-a-* && -e $dir/path/image-ab-*) then
Hope this helps you.

Last edited by bigrigdriver; 11-23-2012 at 02:30 PM.
 
Old 12-02-2012, 07:35 PM   #3
budgie26
LQ Newbie
 
Registered: Nov 2012
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thanks, but my approach didn't work. In the end I had to do the following:

set file1=`ls -l image-a-* | wc -l`
set file2=`ls -l image-ab-* | wc -l`

if ($file1 >1 & $file2 >1) then
script1.pl
else
script2.pl
endif
 
  


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
Use wget to download multiple files with wildcards Anant Khaitan Linux - Networking 8 08-23-2013 10:45 PM
[SOLVED] Assistance with multiple php if statements genderbender Programming 1 07-06-2011 05:08 PM
BASH How while loops handle multiple if statements? DevonB Linux - Newbie 3 12-28-2009 07:13 AM
How do I make a script accept wildcards in arguments? CartersAdvocate Slackware 15 12-12-2008 01:03 AM
SQL: multiple WHERE statements elvijs Programming 2 07-02-2007 10:17 AM


All times are GMT -5. The time now is 12:29 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration