[X-Unix] A little shell scripting help

Philip J Robar pjrobar at areyoureallythatstupid.org
Tue Oct 4 15:47:39 PDT 2005


On Oct 4, 2005, at 8:56 AM, Larry Helms wrote:

> Another EXCELLENT resource for shell scripting newbies...
>
>     http://www.shelldorado.com
>
> Contains tutorials... And a WHOLE BUNCH of exmaples.

I like this site a lot.

Advanced Bash-Scripting Guide by Medel Cooper at <http://www.tldp.org/ 
LDP/abs/html/> also appears to be very good.


> Depending on the shell the (...) construct usually means execute  
> contents
> INLINE.  E.g.
>
> ( ls -1; head -1 )
>
> Each time Unix shells hit a command they really fork off another  
> process to
> perform the task - having used other OSes... I won't even go into  
> that issue
> - anyway... A way to force the routine NOT to do this... Is to  
> enclose the
> commands in ( ) sets.

I'm not sure where you got this inline concept from. All my shell  
books and the web pages I checked say that (...) invokes a subshell,  
i.e. it explicitly forks a new process with a local environment that  
exists till the closing ')'. The point is to be able to set up a new  
temporary environment for just these commands or to be able to run  
commands in parallel. The classic example is using tar piped to tar  
to copy something from one place to another, e.g. tar cf - stuff |  
(cd /some/where/else; tar xf -). This wouldn't work if (...) didn't  
invoke a new process.


Phil



More information about the X-Unix mailing list