Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2002
    Posts
    1,166

    Shell Script - Read Variables From a File

    I am looking for some ideas on how to create a shell script that will read variables from a parameter file ignoring any text that begins with #.

    ie - param file

    #This text will be ignored

    var1='blah'
    var2='foo'
    var3='bar'
    #var4=' ' # this variable will be ignored

  2. #2
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    What do you want to do with the variables?

    PHP Code:
    #!/bin/bash
    echo "Please enter filename:";
    read filename;
    cat $filename |while read line;do
        
    firstchar = ${line:0:1}
        if [ ! 
    $firstchar == "#"]
        
    then
            
    echo $line;
        
    fi
    done 
    Untested, but should work.

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  3. #3
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Looks like the param file just contains standard bash variable assignments / comment lines? If so you can just include it:
    Code:
    #!/bin/bash
    . paramfile
    echo "var1 is $var1"
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  4. #4
    Join Date
    Jun 2002
    Posts
    1,166
    Thanks Chris...that's what I was looking for

Posting Permissions

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