|
|||||||
| 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
|
||||
|
||||
|
File check script fails for multiple files
I want to check if any file with testing*.txt exists but my script fails if more than 1 file exists. It works fine for a single file Code:
if [ -s /tmp/file_checker/testing*.txt ] then echo "TEST21" fi -------------- Code:
bash: [: too many arguments How do I fix this? Thanks
|
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
for f in /tmp/file_checker/testing*.txt; do [ -s "$f" ] && echo TEST21 && break done Note that -s returns true if the file exists and its size is greater than zero. |
| The Following User Says Thank You to radoulov For This Useful Post: | ||
sumang24 (01-30-2013) | ||
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Another approach: Code:
if ls /tmp/file_checker/testing*.txt > /dev/null 2> /dev/null; then echo "TEST21" fi |
| The Following User Says Thank You to Yoda For This Useful Post: | ||
sumang24 (01-30-2013) | ||
|
#4
|
|||
|
|||
|
Quote:
Code:
ls: /tmp/file_checker/testing*.txt: No such file or directory Basically I want to display just the message that the file does not exist: Code:
if ls /tmp/file_checker/testing*.txt > /dev/null; then echo "TEST21" else echo "file does not exist" fi |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Redirect
stderr to
/dev/null like I suggested above: Code:
if ls /tmp/file_checker/testing*.txt > /dev/null 2> /dev/null; then |
| The Following User Says Thank You to Yoda For This Useful Post: | ||
sumang24 (01-30-2013) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Works like a charm. Thanks ---------- Post updated at 12:27 PM ---------- Previous update was at 12:06 PM ---------- Quote:
something like this: Code:
VAR1="FOO" if [ $ORACLE_SID = $VAR1 -a ls /tmp/file_checker/testing*.txt ] > /dev/null 2> /dev/null; then echo "TEST21" else echo "file does not exist" fi Thanks |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
It was outside [ ] before, but you put it in [ ] , where it expects an expression not a command. Code:
if [ "$ORACLE_SID" = "$VAR1" ] && ls /tmp/file_checker/testing*.txt >/dev/null 2>/dev/null then ... else ... fi |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
sumang24 (01-30-2013) | ||
| 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 |
| need a shell script to extract the files from source file and check whether those files existonserve | muraliinfy04 | Shell Programming and Scripting | 13 | 02-22-2012 07:14 AM |
| .sh script / Check for file in two directories then cat the files | Loonatic | Shell Programming and Scripting | 2 | 07-27-2010 12:16 PM |
| 1 script or multiple scripts?? - check files, run jobs | jnanasakti | Shell Programming and Scripting | 6 | 11-05-2008 12:10 PM |
| check the file in multiple Directory in a script | mail2sant | Shell Programming and Scripting | 3 | 09-17-2008 12:44 PM |
| Script to Delete temp files and check file system | Bwood1377 | Shell Programming and Scripting | 3 | 08-14-2008 08:34 AM |
|
|