Find the answer to your Linux question:
Results 1 to 2 of 2
Hello all. This is sending me crazy at the moment. I am writing a bash script that is suppose to log into a server, go to a directory nd check ...
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    39

    array in if body being evaluated reagrdless of condition..

    Hello all. This is sending me crazy at the moment. I am writing a bash script that is suppose to log into a server, go to a directory nd check for the presence of a certain file, which is identified by a date stamp. so i do the following.

    ...

    ssh bwill@theisland "

    cd /home/ToTheIsland

    if [ -e "${file1}" ];
    then
    echo here at file1. They exist
    echo index is ${index}
    : ${missing[$index]="${file1}"}
    : $[index++]
    else
    echo file1 files does not exist!
    fi
    "
    ...

    now my problem is that the array and the indrement in the body of the if gets assigned regardless of the value of the condition. only the echo behave how I expect. What is up with this? is this how bash works? is there a work around. Please help. Thanks..

    -B

  2. #2
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    What is with all the brackets? It shoudl work if

    Code:
    if [ -e "$FILE1" ]; then
       echo "Doing some **** to $FILE1"
    else
       echo "$FILE1 does not exist."
    fi

Posting Permissions

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