I have a, what i think very trivial, problem:
I have a cshell script in which I want to test whether an entry is
either a local file, local directory or a symbolic link.
I know that in bourne shell it is pretty easy to test for a symbolic
link using "test -h" or "test -L" but this doesn't distinguish between
a directory or link in csh!
I tried:
if ( -h <item> ) then
....
but this gives me the following error message: "if: badly formed
number" (apparently the builtin test functionality of the csh doesn't
support this)
So I tried the following construct
if ( ! `test -h <item>` ) then
.....
but as said this can't make a difference between a directory and a
link.
Of course one could extract information about the <item> using the
'ls' command (and do some post processing on the outcome) but I have
the feeling there should be a more direct way to find out.
Any idea is welcome.
Rgds,
Jan Hovius.
> I have a cshell script in which I want to test whether an entry is
> either a local file, local directory or a symbolic link.
>
> I know that in bourne shell it is pretty easy to test for a symbolic
> link using "test -h" or "test -L" but this doesn't distinguish between
> a directory or link in csh!
> I tried:
>
I don't know what -h means for tcsh.
man tcsh(1) gives
f Plain file
d Directory
l Symbolic link (+) *
L Applies subsequent operators in a multiple-opera-
tor test to a symbolic link rather than to the
file to which the link points (+) *
So try:
if ( -l "$1" ) then
echo $1 is a symbolic link
endif
if ( -d "$1" ) then
echo $1 is a directory
endif
Now if you use "-f" it will match either a symbolic link to a plain
file, or a plain file. So test for -l first if you want to distinquish this.
--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Back quotes give you the output of a command, but test has no output,
only an exit status. In csh you can test the exit status of a
command with if { command } .
--
The truth you speak has no past and no future. It is, and that's all it
needs to be.
> Hello,
>
> I have a, what i think very trivial, problem:
>
> I have a cshell script in which I want to test whether an entry is
> either a local file, local directory or a symbolic link.
>
> I know that in bourne shell it is pretty easy to test for a symbolic
> link using "test -h" or "test -L" but this doesn't distinguish between
> a directory or link in csh!
Try
test -h filename -a -d filename
That is, both the directory test and the symbolic test is true.
Villy
> Jan.H...@nsc.com (Jan Hovius) writes:
>
>> I have a cshell script in which I want to test whether an entry is
>> either a local file, local directory or a symbolic link.
>>
>> I know that in bourne shell it is pretty easy to test for a symbolic
>> link using "test -h" or "test -L" but this doesn't distinguish between
>> a directory or link in csh!
>> I tried:
>>
>
> I don't know what -h means for tcsh.
>
It has meaning for the test command which lives in /bin or /usr/bin.
>
> if ( -l "$1" ) then
> echo $1 is a symbolic link
> endif
>
> if ( -d "$1" ) then
> echo $1 is a directory
> endif
>
Which, of course, is the builtin feature for testing file types without
using the test command.
Villy
>> I don't know what -h means for tcsh.
>>
>
> It has meaning for the test command which lives in /bin or /usr/bin.
That was my point. Thanks.
Again, thank you!
Villy Kruse <v...@station02.ohout.pharmapartners.nl> wrote in message news:<slrnce4pl...@station02.ohout.pharmapartners.nl>...