• About Me!!!
  • Its Me!!!

Mani's Weblog

~ Naangalum Sindhippomla!!!

Mani's Weblog

Monthly Archives: May 2006

CAT or REDIRECT

05 Friday May 2006

Posted by Mani in Technical

≈ 2 Comments

Today I had a strange problem. Let me explain…

I want to read a property file and assign values to variables.
My code was like cat prop_file | while read line ; do value=$line; done
print $value

Guess the output I got !!!!
Output: (Nothing) 😦

I and my collegue fought for a looooooooooooooooooooooooong time. Then he asked me to use as follows. Modify the code as:
while read line ; do value=$line; done
print $value

and asked it to run as ./myfile.sh prop_file
Hurraaaaaaaaaaaaaaaaaaaaayyyyyyyyyyy!!!!!!!!!!!!!!
I got the output.

Reason: After some trials he told me that the reason might be: The cat might spawn a new shell and execute the entire while loop inside the shell. So the value might not persist after the end of while.

And this entry is dedicated to Vaidhy (my collegue) … 🙂 Thanks Vaidhy…

Subscribe

  • Entries (RSS)
  • Comments (RSS)

Archives

  • January 2017
  • November 2016
  • November 2015
  • October 2015
  • June 2015
  • May 2015
  • March 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • May 2014
  • January 2014
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • May 2013
  • December 2012
  • March 2012
  • January 2012
  • May 2011
  • April 2011
  • October 2010
  • August 2010
  • July 2010
  • June 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • August 2009
  • June 2009
  • May 2009
  • March 2009
  • December 2008
  • September 2008
  • July 2008
  • June 2008
  • January 2008
  • November 2007
  • October 2007
  • September 2007
  • July 2007
  • May 2007
  • February 2007
  • December 2006
  • November 2006
  • October 2006
  • July 2006
  • June 2006
  • May 2006
  • March 2006
  • February 2006
  • January 2006
  • November 2005
  • October 2005
  • September 2005

Categories

  • Computers
  • Games
    • Candycrush
  • Personal
  • Review
    • Book
    • Movie
    • Software
  • Science
  • Social
    • Culture
  • Sports
    • Cricket
    • Tennis
  • Tamil
  • Technical
    • Android
    • Linux
  • Technology
  • Uncategorized

Meta

  • Register
  • Log in

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy