Subject: listing files without ls
From: Mike Barsalou (mbarsalou@aidea.org)
Date: Tue May 07 2002 - 12:46:12 AKDT
While playing around with scripting, I ran across a trick I thought
worth sharing:
You can use:
echo m*
to do the same as:
ls m*
However, with the echo command, you will get back the m* if there are no
file names that match the expression. This is good because in a script
like this:
#!/bin/bash
filenames=`ls m*`
for foo in filenames;
do
echo $foo
done
you would get an error of 'no such file or directory' from your script.
With the echo you would get 'm*'. So you could add a conditional like
this:
#!/bin/bash
filenames=`echo m*`
if [ "$filenames" == "m*"]
then
for foo in filenames;
do
echo $foo
done
else
Echo "There aren't any"
fi
Just thought I would share.
Mike
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
This archive was generated by hypermail 2a23 : Tue May 07 2002 - 12:45:22 AKDT