* Something for the FAQ ?
@ 1993-09-14 9:56 gjv%atlas%cesar
0 siblings, 0 replies; only message in thread
From: gjv%atlas%cesar @ 1993-09-14 9:56 UTC (permalink / raw)
To: rc%hawkwind.utcs.toronto.edu%m_internet%m_mailnow%hermes.DECnet
Hello all,
I was just wondering, is there a collection of useful functions somewhere?
I found some in the FAQ and in the mail list archive of course, but I
assume that there are a lot more useful things out there, which could
be made more accessible when added to the FAQ for example. What made me
think of this is the following:
I'm using the prompt function for the initialisation of interactive
subshells, but this makes $status unusable if you aren't careful.
I came up with the following, which seems to work nicely. (init
is a function to initialise the subshell).
fn prompt {
s=$status {
if ( ! ~ $ipid $pid ) {
ipid=$pid
# one time call to init_shell(), initialises interactive subshell
init_shell
}
return $s
}
}
You can't simply save&restore $status, since the assignment to $status
itself would change the status.
I also wrote the next functions in order to be able
to clean up my $path (removing duplicates), or to remove an entry.
# remove(varname, elt) removes elt from $varname
fn remove {
vn=$1 e=$2 o=() *=$$vn{
while( ! ~ $#* 0)
{
~ $*(1) $e || o=($o $*(1) )
shift
}
$vn=$o
}
}
# clean(varname) removes all double entries from $varname, keeping the first
fn clean {
vn=$1 o=() *=$$vn{
while( ! ~ $#* 0)
{
~ $o $*(1) || o=($o $*(1) )
shift
}
$vn=$o
}
}
# example
clean path
remove path /usr/bin
The only thing to add is the support for ':' separated lists,
like MANPATH,FONTPATH,HELPPATH,LD_LIBRARY_PATH which don't have a
list-equivalent like PATH/path.
Thought it might be useful to have this kind of stuff in a place where
it can easily be found, like the FAQ for example.
Gert-Jan
---------------------------------------------------
J.G. Vons E-Mail: vons@cesar.crbca1.sinet.slb.com
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1993-09-14 9:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-09-14 9:56 Something for the FAQ ? gjv%atlas%cesar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).