Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, Seems funny but I am stuck at a point !! I am wtrying to write a simple sheel script in which I assign a value to a variable from ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    6

    [SOLVED] Assign Variable vaue from a File.

    Hi,

    Seems funny but I am stuck at a point !!

    I am wtrying to write a simple sheel script in which I assign a value to a variable from a file:
    Code:
    #!/bin/bsh
    DIR=/home/sappel
    COM_FILE=$DIR/Test.txt
    var_1=`cat $COM_FILE`
    if [$var_1 = 0]
    then
     echo "This is a Primary LB"
    else
     echo "This is a secondary LB"
    fi
    The ouptput when i run this is :

    [0: not found
    This is a secondary LB

    Whereas the output should be "This is a Primary LB" as the value in the files is 0.

    bash-2.05$ cat Test.txt
    0


    Please help !!
    Last edited by devils casper; 08-04-2008 at 12:16 PM. Reason: Added [code]....[/code] tag.

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    * Spelling mistake in first line. /bin/bash
    * There must be Space before and after [ ].
    * It should be == instead of =.

    Code:
    #!/bin/bash
    DIR=/home/sappel
    COM_FILE=$DIR/Test.txt
    var_1=`cat $COM_FILE`
    if [  $var_1 == 0 ]
    then
    echo "This is a Primary LB"
    else
    echo "This is a secondary LB"
    fi
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    6
    aahhh..Thanks Mate !! that helped

Posting Permissions

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