On Aug 2, 2015, at 8:49 AM, [email protected] wrote:

>> never  
>> thought of using a shell function in .profile till I read this thread.  
> 
> ...
> 
> Functions has always been impressive once you move past the alias
> shortcomings (can't handle arguments etc), so also worth a read the
> "Functions" section.


Functions have been amazingly useful and impressive for a very long time.  They 
are also not limited to ksh.  In fact, my introduction to this very useful 
aspect of shell programming was from Sun's rcS script, which has this:

# Simulates cat in sh so it doesn't need to be on the root filesystem.
#
shcat() {
        while [ $# -ge 1 ]; do
                while read i; do
                        echo "$i"
                done < $1
                shift
        done
}


There have been times when I've been on systems in single user mode without 
filesystems, and knowing how to do some things we typically use external 
programs for in the shell can be a lifesaver, like "echo *" as a poor man's 
"ls".

If your directory isn't *that* large, 'for i in *;  do echo $i; done | wc -l' 
works well.  Well, for some definition of 'well'.

My point is that shell functions allow you to do some fairly complex stuff, and 
if you're careful, you can avoid execs.  There are places the shell forks, 
however.  It can be a fun exercise to find them with profiling tools. :-)

Sean

Reply via email to