Find the answer to your Linux question:
Results 1 to 3 of 3
#!/bin/sh echo -n "enter path of directory > "; read DIRECTORY echo -n "enter name and path of file 1 > "; read FILE1 echo -n "enter name and path ...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    2

    Angry [SOLVED] why?????

    #!/bin/sh

    echo -n "enter path of directory > ";
    read DIRECTORY

    echo -n "enter name and path of file 1 > ";
    read FILE1

    echo -n "enter name and path of file 2 > ";
    read FILE2



    if [ "$DIRECTORY" -a "$FILE1" -a "$FILE2"]
    then
    echo "all paths have been entered"
    else
    echo "not all paths have been entered"
    fi


    if [ -d $DIRECTORY]
    then
    echo "$DIRECTORY ok"
    else
    echo "$DIRECTORY not ok"
    fi


    if [ -f $FILE1]
    then
    echo "$FILE1 ok"
    else
    echo "$FILE1 not ok"
    fi

    if [ -f $FILE2]
    then
    echo "$FILE2 ok"
    else
    echo "$FILE2 not ok"
    fi

    why doesn't this work?!?!?
    i'm using bourne shell and just want the user to enter and directory and two paths and the script to say whether they exist or not. thanks in advanced!

  2. #2
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Welcome to the forums!

    Your script will fail at several points actually. All have to do with syntax. You seem to be missing a lot of (mandatory) white spaces between your variables and the closing ']'.

    For example:
    You wrote: if [ -d $DIRECTORY]
    Should be: if [ -d $DIRECTORY ]
    Can't tell an OS by it's GUI

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    2
    Thanks! it working now..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...