[Linux-disciples] check script arguments for directory
Stephen R Laniel
steve at laniels.org
Fri Jan 19 12:37:56 EST 2007
On Fri, Jan 19, 2007 at 11:58:20AM -0500, Jamie Forrest wrote:
> Is there a way to check that an argument passed to a shell script is
> a directory and not just an ordinary file?
See the manpage for test(1) -- specifically the '-d' test.
E.g.,
(12:44) slaniel at slaniel-laptop:~$ (test -d /etc/passwd) || echo "Not a directory"
Not a directory
(12:45) slaniel at slaniel-laptop:~$ (test -d /etc) || echo "Not a directory"
(12:45) slaniel at slaniel-laptop:~$
I hope that's clear.
There are shorter ways than using test(1), like
if [ -d /etc/passwd ]; then
echo "/etc/passwd is a directory"
fi
--
Stephen R. Laniel
steve at laniels.org
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20070119/1ef3c22b/attachment.pgp
More information about the Linux-disciples
mailing list