Hi.
The real question appears to be:
Quote:
|
How do I recognize if a given new place is a directory or file or directory with file?
|
The fact that a string ends in a slash does not mean that the string refers to a directory.
If that is a fair assessment, then I would recommend testing the string to see if it does refer to a directory or not. Using
test or
[ with the predicate
-d is of value here. Of course, you may wish to do more detailed testing.
For example:
Code:
#!/bin/sh
# @(#) s1 Demonstrate test for directory.
# Clear debris.
rm -rf d1 t1 j1
isdir()
{
local ITEM="$1"
if [ -d "$ITEM" ]
then
return 1
else
return 0
fi
}
echo
echo " Current items:"
touch t1
mkdir d1
ls -ld d1 t1 j1
echo
echo " Testing both items:"
FILE=./t1
if isdir "$FILE"
then
echo " Item $FILE is NOT a directory."
else
echo " Item $FILE is a directory."
fi
FILE=./d1
if isdir "$FILE"
then
echo " Item $FILE is NOT a directory."
else
echo " Item $FILE is a directory."
fi
FILE=./j1
if isdir "$FILE"
then
echo " Item $FILE is NOT a directory."
else
echo " Item $FILE is a directory."
fi
Which results in:
Code:
% ./s1
ls: j1: No such file or directory
Current items:
drwxr-xr-x 2 makyo makyo 48 Jan 26 17:35 d1
-rw-r--r-- 1 makyo makyo 0 Jan 26 17:35 t1
Testing both items:
Item ./t1 is NOT a directory.
Item ./d1 is a directory.
Item ./j1 is NOT a directory.
Best wishes ... cheers, makyo