Karim Vaes

Why chop at leaves, when one must dig at roots
  • Home
  • About me
    • Curriculum Vitae
  • Scripts
    • OWA Most Popular
  • Search
  • License
  • Contact

Bash subshell & piping to a loop

When setting/changing variables within the scope of a subshell. And then attempt to use those variables outside the scope of this subshell won’t give the ‘expected result’.
A subshell has to be seen as a totally seperate process with it’s own environment.
(check a previous entry about processes)

Now the above might seem logical: Subshell, seperate process, … okay. Let’s say you want to pipe the output of a certain command thru a loop. In this loop you can manipulate/filter/… the data. In some cases you might want to set a flag if a certain criteria is met. Here is where it all comes into play. When you pipe an output to any kind of loop, it’ll become a subshell.

So as you might have guessed. The flag you wanted to set won’t cross it’s subshell borders. So you won’t be able to see it outside the loop. And yet again, an output that you might not have expected.

More info about “bash gotchas” can be found here

Comments
3 Comments »
Categories
Bash, Unix/Linux
Comments rss Comments rss
Trackback Trackback
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Next Entries »

Recent Posts

  • Treating the root cause to cancer
  • Is “entrepreneur” a bad word?
  • Where physics meets marketing
  • Where USSR meets IT?
  • Accepting our limitations, is giving us the opportunity to overcome them!

Similar Posts

  • bash : locking issues – example with setlock
  • Wrapperscript around ghettoVCB
  • Simple Drupal Ajax Forms (version 0.2)
  • Drupal : Three simple steps to adding ajax to your drupal forms/pages
  • The octaldump of the unix2dos / dos2unix

Recent Comments

  • Karim Vaes on Accept every offer!
  • Danny on The teachings of Budo in Business
  • Pascal on The Service Catalog
  • Shubert on WordPress widget : Most popular posts
  • Dermana Agrı Kesici Krem on OWA Most Popular

Commercial

Categories

2.0 Ads Agile Bash Blogroll Book Brain Business Career Change CIO Collaboration Communication Corner Creative CRM Culture Desktop Development Dreambox Drupal Education Entrepreneur F5 Firefox Food Freelance Fun General Green Growth High Availability Human Resources Idea Infrastructure Insightful Interesting IT ITIL Java Lesson License Life Malware Management Mind Model Motivation MythTV Network NLP OpenSource Performance PHP PM Presentation Project Proverb Quote Remote Scrum Security SEO Social Spam Storage Stress Tactical Team Tech TED Time Management Tip Tool TV Ubuntu Unix/Linux Vids Vim Virtual VmWare Voip Web Wordpress

Archives

  • August 2010
  • July 2010
  • May 2010
  • April 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • August 2009
  • July 2009
  • June 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
rss Comments rss valid xhtml 1.1 design by jide licensed as Creative Commons Attribution