regards,
Ben
--
BTW. I can be contacted at Username:newsgroup4.replies.benaltw
Domain:xoxy.net
to avoid stderr output on failure.
Ben
--
BTW. I can be contacted at Username:newsgroup4.replies.benaltw
Domain:xoxy.net
> to avoid stderr output on failure.
> Ben
if [[ -n $(ls test* > /dev/null 2>&1) ]]; then
To avoid stdout output on success :-)
Or more simply
ls test* >/dev/null 2>&1 && echo found it
Joe
> > > if [[ -n $(ls test*) ]]; then
> > if [[ -n $(ls test* 2> /dev/null) ]]; then
> > to avoid stderr output on failure.
> > Ben
> or
> if [[ -n $(ls test* > /dev/null 2>&1) ]]; then
> To avoid stdout output on success :-)
Never mind, I haven't had my coffee yet this morning.
Quote:> Or more simply
> ls test* >/dev/null 2>&1 && echo found it
> Joe
> if [[ -n $(ls test*) ]]; then
>>>I want to check if there exist any filename with test in it by
>>>if [[ -a test* ]]; then
>>> echo "file exist"
>>> else
>>> echo "file not exist"
>>>fi
>>>But it always return not exist. How can I use wildcard in check the
>>>existence of certain type of files? Thanks.
>> if [[ -n $(ls test*) ]]; then
> Why use "ls" which causes shell to fork()?
regards,
Ben
--
BTW. I can be contacted at Username:newsgroup4.replies.benaltw
Domain:xoxy.net
> Why use "ls" which causes shell to fork()?
regards,
Ben
--
BTW. I can be contacted at Username:newsgroup4.replies.benaltw
Domain:xoxy.net
>>>>I want to check if there exist any filename with test in it by
>>>>if [[ -a test* ]]; then
>>>> echo "file exist"
>>>> else
>>>> echo "file not exist"
>>>>fi
>>>>But it always return not exist. How can I use wildcard in check the
>>>>existence of certain type of files? Thanks.
>>> if [[ -n $(ls test*) ]]; then
>> Why use "ls" which causes shell to fork()?
>Guess.
shopt -s extglob 2>/dev/null
echo "no files that matches test*"
else
echo "there are 1 or more files that matches test*"
fi
--
> shopt -s extglob 2>/dev/null
> echo "no files that matches test*"
> else
> echo "there are 1 or more files that matches test*"
> fi
regards,
Ben
--
BTW. I can be contacted at Username:newsgroup4.replies.benaltw
Domain:xoxy.net
: I want to check if there exist any filename with test in it by
: if [[ -a test* ]]; then
: echo "file exist"
: else
: echo "file not exist"
: fi
: But it always return not exist. How can I use wildcard in check the
: existence of certain type of files? Thanks.
:
:
x=0
for i in test*
do
[[ -a $i ]] || continue
x=1
done
if [[ $x -ne 0 ]]
then
echo file exists
else
echo file does not exist
fi
Kudos if you can tell me why you use "|| continue"
instead of "|| break"
Dan Mercer
>> if [[ -n $(ls test*) ]]; then
> if [[ -n $(ls test* 2> /dev/null) ]]; then
if ls test* >/dev/null 2>&1; then
Regards,
Ed.
Ben
--
BTW. I can be contacted at Username:newsgroup4.replies.benaltw
Domain:xoxy.net
>> Why use "ls" which causes shell to fork()?
>The non-forked method I thought of is on the convoluted side, but the
>above is nice and clear.
--
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
>>> Why use "ls" which causes shell to fork()?
>>The non-forked method I thought of is on the convoluted side, but the
>>above is nice and clear.
>Couldn't you just use "echo" instead of "ls"? Why does it need to be
>convoluted?
I provided a non-forked and non-convoluted method in a separate post.
--
1. A script that will only check file if it has been modified since last check
I have a script that greps the /var/adm/messages file for a pattern, write
it to a file. Then emails me a warning.
The thing is I want to run this regularly, and the messages file is not
rotated regularly. How do I add this to the script that I only want it to
grep the file and email me if there is a new "pattern" not the same
"pattern" from an hour ago, or yesterday.
grep "currently marked as unusable" $ADMSG > $TEMP
grep "No more IP addresses on 192.168.2.0 network" $ADMSG >> $TEMP
if [ -s $TEMP ]
then
/usr/sbin/pntadm -P 192.168.2 >> $TEMP
fi
#rm -f $TEMP
Yes, a will be installing a logchecker, but for now this is what I have time
for...
4. Complete O'Reilly X Programming Series on Ebay
5. Check file size before ftp-ing
6. No verticle alignment in tabular
7. Script that recurses through all directories tries to check file/directory named "*"
9. Check file access right of other user
11. Question: Checking Files Open by Other Processes.
12. Check file format (dos or unix)
13. How to check file size and create date < 24hr?