Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-22-2012, 08:58 PM   #1
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
echo "no files found"

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

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

Last edited by bigrigdriver; 11-23-2012 at 01:30 PM.
Old 12-02-2012, 06:35 PM   #3
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


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 09:45 PM
[SOLVED] Assistance with multiple php if statements genderbender Programming 1 07-06-2011 04:08 PM
BASH How while loops handle multiple if statements? DevonB Linux - Newbie 3 12-28-2009 06:13 AM
How do I make a script accept wildcards in arguments? CartersAdvocate Slackware 15 12-12-2008 12:03 AM
SQL: multiple WHERE statements elvijs Programming 2 07-02-2007 09:17 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:55 AM.

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