Results 1 to 4 of 4

Thread: Populate an array in script plz

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    34

    Default bash script array

    i have searched for this already, bare with me!!!

    Im having trouble guys, can anyone refresh me on how to populate an array with the output of this command?

    iwlist ath0 scanning | awk -F '[ :=]+' '/(ESS|Freq|Qual)/{ printf $3" " } /Encr/{ print $4 }'
    im trying to use the output of iwlist so i can have auto-detected variables of current access points. If i'm going about this totally wrong, any help would be appreciated thanx


    :::fixed

  2. #2
    Junior Member
    Join Date
    Jan 2010
    Posts
    34

    Default not fixed

    oh no still having a problem. I decided to do this instead

    Code:
    varnets=$(iwlist ath0 scanning | awk -F '[ :=]+' '/(ESS|Qual)/{ printf $3" " } /Encr/{ print $4 }')
    which gives me this inside one variable--varnets
    Code:
    "belkin54g" 38/70 off
    "2WIRE082" 8/70 on
    "2WIRE330" 11/70 on
    "davis2wire" 19/70 on
    I don't know how to seperate them into different variables. example:
    $essid1,2,3,4...
    so if i "echo $essid2" it echoes "2wire082"

    Can any super scripter lead me in the right direction or even spoon me a break? I am new to shell scripting but want to learn. this is only the part im stuck on and would like to move on but i can't call my network variables!!

  3. #3
    Developer
    Join Date
    Mar 2007
    Posts
    6,126

    Default

    you have to parse the list and use cut or sed to cut out only the essid and then add it to a variable

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    34

    Default

    thanx, using cut:

    Code:
    varnet=$(iwlist ath0 scanning | awk -F '[ :=]+' '/(ESS|Qual)/{ printf $3" " } /Encr/{ print $4 }' | cut -d " " -f1)
    I can now get:
    Code:
    "belkin54g"
    "2WIRE082"
    "2WIRE330"
    "davis2wire"
    im currently reading man pages and google for info on setting cut so it cuts this vertically along with horizontally. wish me luck' im nooby on this!

    Okay:
    cut and head seem to be useful tools for this:
    cut -d" " -f 1 | head -1

    Now if i can just automate this for each line so that each goes to a variable, perhaps somehow using ++ after head -1????

Posting Permissions

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