• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading in (redirecting command output) into variable

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic