LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-27-2011, 04:19 AM   #1
dzaku
LQ Newbie
 
Registered: Jun 2011
Location: POLAND BOAT CITY
Distribution: ARCH-LINUX, DEBIAN, FEDORA, UBUNTU
Posts: 9

Rep: Reputation: Disabled
[bash] sting as variable


Hi
I try set a string element, as variables

Code:
my example :

    for COUNT_IFE in $LIST_IFE
    do
 
       ${COUNT_IFE}="$(echo "$MENU" | grep $(echo $COUNT_IFE) | awk -F' ' '{print  $10 }')"
     
    done
but concole replece me to tty

./pies2.sh: line 19: eth0=5851184659: nie znaleziono polecenia

(translation: command ot found )

Last edited by dzaku; 06-27-2011 at 04:33 AM.
 
Old 06-27-2011, 05:03 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It is not clear what you're trying to do. However, the left-hand side of an assignment should not have the reference to a variable, but the name of the variable itself, that is
Code:
COUNT_IFE=blahblahblah
instead of
Code:
${COUNT_IFE}=blahblahblah
Moreover, changing the loop variable inside the loop itself has not much sense. Please, show us what is the value of the variables LIST_IFE and MENU, and try to describe what this code is supposed to do.
 
Old 06-27-2011, 05:32 AM   #3
dzaku
LQ Newbie
 
Registered: Jun 2011
Location: POLAND BOAT CITY
Distribution: ARCH-LINUX, DEBIAN, FEDORA, UBUNTU
Posts: 9

Original Poster
Rep: Reputation: Disabled
I writing simple loger form interfaces


Code:
function VARY_IFE {
    ix=0
    for COUNT_IFE in $LIST_IFE
    do

       ${COUNT_IFE}[0]=$(echo "$MENU" | grep $(echo $COUNT_IFE) | awk -F' ' '{print  $10 }')
       ${COUNT_IFE}[1]=$(echo "$MENU" | grep $(echo $COUNT_IFE) | awk -F' ' '{print  $2 }')

       #echo $COUNT_IFE
        ix=$[$ix+1]
    done
}
#Predefined variables
SAVE_F="/tmp/bps_rx.dat"
INAME=$(uname -a | cut -d" " -f2)
ROAD_TO_FILE="/proc/net/dev"
##################Main code
           MENU=$(cat /proc/net/dev)
           _IFE=$(echo "$MENU" | awk '{print $1}')
           NUM_IFE=$(( $(echo "$_IFE" | wc -l ) - 3 ))
           LIST_IFE=$(echo "$_IFE" | tail -$NUM_IFE | sed 's/[:]/ /g' )
            VARY_IFE
           sleep 5
 
Old 06-27-2011, 06:20 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Ok. The first problem is what stated in my post above: remove the $ sign form the LHS of the assignments and see if it works as you expect.
 
1 members found this post helpful.
Old 06-27-2011, 07:27 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
So obviously I am a little bit uncertain as to what your code will eventually achieve, but from what i have followed, the following does all that you have done so far:
Code:
COUNT_IFE=($( awk 'NR > 3{print $2,$10}' /proc/net/dev))
 
1 members found this post helpful.
Old 06-27-2011, 09:09 AM   #6
dzaku
LQ Newbie
 
Registered: Jun 2011
Location: POLAND BOAT CITY
Distribution: ARCH-LINUX, DEBIAN, FEDORA, UBUNTU
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
So obviously I am a little ....


I want write simple script for generate charts (gnuplot) from all interfaces in workstation or server. @Grail you idea is great, I just read how to redirect a variable to awk
Thansk for help colucix and grail
 
Old 06-27-2011, 09:31 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by grail View Post
Code:
COUNT_IFE=($( awk 'NR > 3{print $2,$10}' /proc/net/dev))
That's an ingenious technique, grail, using an array assignment to parse out the first word and then using the array variable name without a subscript to dereference the first member of the array
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] re-evaluate variable inside variable muzzol Programming 9 12-01-2010 11:31 AM
Bash: How do I read data from a variable while that variable is being populated? theaceoffire Programming 4 04-23-2010 02:29 PM
-bash: HISTSIZE: readonly variable -bash: HISTFILESIZE: readonly variable deathsfriend99 Linux - Newbie 4 12-08-2009 12:51 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 01:15 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 03:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration