Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I have a certain number, let's say $n, of input files *.inp for a software i use. For each of them I'll get an output file, *.out. These output ...
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8

    compare two env variables

    Hi,

    I have a certain number, let's say $n, of input files *.inp for a software i use.
    For each of them I'll get an output file, *.out. These output files are, all together, an input for a second software I use.
    For this reasons, I collect all the output files in a folder, let's say pop_folder.
    Before I run the second software I have to make sure that the first one runs successfully and all .out files joined the pop_folder.

    i'm trying something like that:

    cd pop_folder

    while something=true;
    do
    sleep 10
    m=$(ls -l *.out | wc -l)
    echo $m
    echo $n

    if test ["$n"="$m"]
    then
    echo "entering if...."
    make job
    something=false

    fi
    done

    in my display I get:

    0
    3
    entering if..

    it seems that my if condition is true despite the actual values of $n and $m.
    What's wrong??

    thanks in advance for any suggestion.

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    Code:
    something=true
    This is an assignment and will always be true =>

    Code:
    while "$something"="true"
    
    #and later on
    something="false"
    Code:
    if test ["$n"="$m"]
    You are making 2 tests =>
    Code:
    #Either
    if [ "$n" = "$m" ]
    #or
    if test "$n" = "$m"
    #note the white spaces
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8
    it works! Thanks a lot!

    by the way.. why does the blank space make the difference?

  4. #4
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    The '[' is a command, /usr/bin/[ and works as /usr/bin/test
    Everything that follow are arguments, which must therefore be separated by white spaces. The last argument must be ']'.
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

Posting Permissions

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