LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-06-2005, 07:47 AM   #1
sachinh
Member
 
Registered: Jul 2004
Location: india
Distribution: RH
Posts: 189

Rep: Reputation: 30
Simple shell script query


Hi GuRU's ,


Got a simple query . I'm using Linux AS 2.1 os . Want to capture current memory utilisation ( used , free and used-swap ) into different variables in the shell script . So that based on these variable values I can execute some commands . Please guide .
 
Old 09-06-2005, 07:51 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,430

Rep: Reputation: 203Reputation: 203Reputation: 203
do

Code:
set --  `command`
and whatever the output is will populate $1 $2 $3 ... etc.
 
Old 09-06-2005, 10:03 AM   #3
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
or read:
Code:
read a b c d ... < <(command)
Yves.
 
Old 09-06-2005, 10:15 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,430

Rep: Reputation: 203Reputation: 203Reputation: 203
typo yeti?

 
Old 09-06-2005, 12:07 PM   #5
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
No no Let's assume you want to read the 3 fields returned by command command, then you'd write:
Code:
read field1 field2 field3 < <(command)
The first '<' is to say: `read`'s input should be the said file instead of standard input.
The second '<' is actually '<( ... )' and is a clever trick of bash programming, by which the result of a command is seen as a file: this is called "process substitution".

And even better, you can input your fields in an array!
Code:
read -a fields < <(command)
Yves.
 
Old 09-07-2005, 04:02 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,430

Rep: Reputation: 203Reputation: 203Reputation: 203
Aah!

I've learnt something new!

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Simple Shell Script Help Kristijan Programming 3 06-13-2005 09:13 PM
simple shell script sharpie Programming 9 06-02-2004 11:47 PM
simple shell script Greg_courageous Programming 2 05-12-2004 04:34 PM
a simple shell script Warchief Programming 1 07-31-2003 05:01 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

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

All times are GMT -5. The time now is 05:23 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration