basics - if condition (contains)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers basics - if condition (contains)
# 1  
Old 03-26-2007
basics - if condition (contains)

Can any body help me on how to check whether a file contains a required extension or not.

pseudo is:

if (filename contains .jpg || filename contains .gif)
--- do some thing
end if

Example file names:
test1.grm.gtrx.drx.jpg
test.de.mi.jpg
test2.ds.gif
test3.gif

thanks in advance
# 2  
Old 03-26-2007
Somebody suggested in one of the messages and with that, could make it like this:

suffix=${filename##*.}

if [ $suffix = "jpg" || $suffix = "gif" ]; then
-- do something
fi
# 3  
Old 03-27-2007
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX basics

Hi, I am new to Unix. can you explain in brief with examples what is variable, what is argument and what is parameter? i searched a lot on other forums but not able to find a appropriate answer. thanks in advance!! (3 Replies)
Discussion started by: 21laps
3 Replies

2. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. UNIX for Dummies Questions & Answers

UNIX Basics

Hello, 1) I am trying to get involved in UNIX for educational purposes so I have installed the latest Ubuntu edition 12.04. Do you know another package that I could use it instead for educational purposes? 2)What is the difference between "~$" and "/$" (it comes with cd / and cd ~) .The... (1 Reply)
Discussion started by: Iwn
1 Replies

4. UNIX for Dummies Questions & Answers

help me with basics

hello everyone i have to start with unix as it is a part of my training programme and i have to do a self study, i dont know where to start from. i need some basic questions to be answerd like why we use unix ? what is a terminal? what is an editor? why we write commands inside terminal? these... (4 Replies)
Discussion started by: aryancool
4 Replies

5. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

7. UNIX for Dummies Questions & Answers

awk basics

Hi, Please tell me where can I get started with awk..like the basics and the whole awk stuff. Regards, Deepti (2 Replies)
Discussion started by: gaur.deepti
2 Replies

8. Shell Programming and Scripting

awk basics

what is wrong with the code below; it starts ,then does nothing, (even it doesn't end) #!/bin/awk x=1 b="foo" awk printf("%s got a %d on the last test\n","Jim",83) myout=("%s-%d",b,x) print myout (6 Replies)
Discussion started by: gfhgfnhhn
6 Replies

9. Shell Programming and Scripting

Shell basics

Hi All, I have a basic question in Scripting. Can anyone tell me what is the difference b/w the two syntax : if (( $lines = 0 )); and if ; when do we use the square brackets & when to use the paranthesis. Thanks, Pradeep (3 Replies)
Discussion started by: pradeep_desh
3 Replies
Login or Register to Ask a Question