Results 1 to 3 of 3

Thread: Bash script - loop question

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Bash script - loop question

    Hi Folks,

    I have a loop that goes through an array and the output is funky.

    sample:
    array=( 19.239.211.30 )
    for i in "${array[@]}"
    do
    echo $i
    iperf -c $i -P 10 -x CSV -f b -t 50 | awk 'END{print '$i',$6}' >> $file
    done

    Output:
    19.239.211.30
    19.2390.2110.3 8746886

    seems that when the $i after the awk is printed something happens to it.

    Any ideas?

    Thanks.

  2. #2
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Answered my own question:


    replace '$i' with ${i} = win

  3. #3
    Senior Member cfajohnson's Avatar
    Join Date
    May 2009
    Posts
    190
    Thanks
    0
    Thanked 44 Times in 36 Posts
    Rep Power
    10

    Default

    Quote Originally Posted by nitrohuffer2011 View Post
    Answered my own question:

    replace '$i' with ${i} = win
    The braces don't do anything. Just quote variable references, e.g.:
    Code:
    echo "$i"
    Chris F.A. Johnson <http://cfajohnson.com/shell/>
    Shell programmer and author

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Bash script - loop question
    By nitrohuffer2011 in forum Coding in General
    Replies: 0
    Last Post: 29th June 2013, 03:57 AM
  2. [Solved] Bash script that asks the user how many times they want to loop
    By chicom0341 in forum Shell scripting
    Replies: 4
    Last Post: 7th November 2012, 01:11 AM
  3. Use Bash for loop file contents
    By chinalinix in forum Shell scripting
    Replies: 6
    Last Post: 4th November 2011, 06:25 PM
  4. for loop question
    By billconner in forum Shell scripting
    Replies: 10
    Last Post: 24th August 2010, 01:58 AM
  5. Problems with for loop( bash shell )
    By shell_chan in forum Shell scripting
    Replies: 1
    Last Post: 26th July 2009, 05:49 PM

Posting Permissions

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