|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Checking existence of file using file pattern
Hi Experts
,I need to check the existense of file using patterns.How can i do it? Ex: if my current directory has a number of files of pattern (ins_*), i need to check the existense of atleast one file. pls reply me. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
This seems to work for me. There may be (and probably is) a better way to do it. Code:
if test -n "$(ls ins_*)"; then echo "yep"; else echo "nope"; fi |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
ShawnMilo's response is pretty good, I think. Just to be sure, you might want to use: Code:
if test -n "`/bin/ls -1 ins_* 2>/dev/null`"; then echo "yep"; else echo "nope"; fi Otherwise, you'll get a "file not found" error, or if your output starts with a dash, you'll have problems. |
|
#4
|
|||
|
|||
|
Thanks a lot ShawnMilo & Otheus...!
![]() Thanks a lot ShawnMilo & Otheus...! Its working fine. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checking existence of file using awk | manish007 | Shell Programming and Scripting | 6 | 01-23-2012 02:41 PM |
| checking the file existence using ssh | ramesh12621 | Shell Programming and Scripting | 6 | 03-07-2011 09:13 AM |
| Multiple file existence and checking file size | lathish | Shell Programming and Scripting | 2 | 06-29-2008 12:03 PM |
| Checking the existence of a file.. | igandu | Shell Programming and Scripting | 7 | 06-13-2007 03:47 AM |
| checking file existence | DILEEP410 | Shell Programming and Scripting | 3 | 01-24-2007 11:43 AM |
|
|