Shell programming problem

Hi,
I am trying to find out if a file input by
the user is file or a directory ?
ls -l has the first field as the info I want
drwxr-xr-x

This is what I wrote

echo "Enter the name of a file"
set file = $<
set command = `ls -l $file`
set directory = $command[1]
echo $directory

I get " drwxr-xr-x " but I want to decode this further to extract "d" or "-". Can anyone explain how this can be done ?
Thanks
Kapil

Comments

  • : Hi,
    : I am trying to find out if a file input by
    : the user is file or a directory ?
    : ls -l has the first field as the info I want
    : drwxr-xr-x
    :
    : This is what I wrote
    :
    : echo "Enter the name of a file"
    : set file = $<
    : set command = `ls -l $file`
    : set directory = $command[1]
    : echo $directory
    :
    : I get " drwxr-xr-x " but I want to decode this further to extract "d" or "-". Can anyone explain how this can be done ?
    : Thanks
    : Kapil
    :

    Hi...
    Try to test the argument with if then... else exit or something lijke that...

    Here is a list of file test operators.

    -b file True if file is a block device
    -c file True if file is a character special file
    -d file True if the file is a directory
    -f file True if file is a ordinary file
    -r file True if file is readable by process
    -w file True if file is writeable by process
    -x file True if file is executable

    Hope this helps,
    bye
    Christian
  • Thanks a lot,
    Thats exactly what I wanted,
    Regards
    Kapil

    : : Hi,
    : : I am trying to find out if a file input by
    : : the user is file or a directory ?
    : : ls -l has the first field as the info I want
    : : drwxr-xr-x
    : :
    : : This is what I wrote
    : :
    : : echo "Enter the name of a file"
    : : set file = $<
    : : set command = `ls -l $file`
    : : set directory = $command[1]
    : : echo $directory
    : :
    : : I get " drwxr-xr-x " but I want to decode this further to extract "d" or "-". Can anyone explain how this can be done ?
    : : Thanks
    : : Kapil
    : :
    :
    : Hi...
    : Try to test the argument with if then... else exit or something lijke that...
    :
    : Here is a list of file test operators.
    :
    : -b file True if file is a block device
    : -c file True if file is a character special file
    : -d file True if the file is a directory
    : -f file True if file is a ordinary file
    : -r file True if file is readable by process
    : -w file True if file is writeable by process
    : -x file True if file is executable
    :
    : Hope this helps,
    : bye
    : Christian
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories