aspose file tools*
The moose likes Linux / UNIX and the fly likes reading in (redirecting command output) into variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "reading in (redirecting command output) into variable" Watch "reading in (redirecting command output) into variable" New topic
Author

reading in (redirecting command output) into variable

Mike Smith
Ranch Hand

Joined: Sep 23, 2005
Posts: 85
Hello all,
I am wondering how it is possible to do the following:
set month=`date | cut -c5-7`
set userInfo=`last "$1" | grep "$month"`
echo $userInfo <---- how do I to put each line on a separate newline? SO that when I echo this variable (echo $userInfo)- It displays identically to just invoking the last command. For example, last username. At the present time, when this command is invoked it appends each new line to the preceding line. I need to iterate over the contents stored in this variable to process the times(add them).

Some background;
I am trying to write a sh script to count how many hours a given user has used the system since this month. However, I run into a sling when I try to use a for loop. I believe I need to correct the problem of echo $userInfo displaying each line as a separate line to use in the for loop; but not 100% certain. I know I need to process the login times from the last command in a for loop and add them(just increment the sum of a variable). And I know that I'll have to implement an if elif clause to test different critera. Any suggestions, greatly appreciated.
Thanks in advance.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923


perhaps the sed-command isn't what you like.

The "(" and ")" are only used to clarify what is read when.

I'm not writing much shellscripts, so this was a nice exercise to me.

I use the advanced bash scripting guide to solve problems:
http://personal.riverusers.com/~thegrendel/abs-guide-4.2.tar.bz2
[ March 18, 2007: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading in (redirecting command output) into variable