> How to use functions in csh scripts ?
Add the line
#!/usr/bin/ksh
to the top of the script, and adjust syntax accordingly.
Otherwise, put each "function" in a separate script and call that,
putting up with the overhead of starting a new process everytime you
call a subroutine. The first option is better though.
From a while ago, a post from Brian Hiles:
----- Original Message -----
From: "Brian Hiles" <b...@rawbw.com>
Newsgroups: comp.unix.shell
Sent: Tuesday, August 07, 2001 6:48 PM
Subject: Re: csh function syntax?
kim <kim.w...@compaq.com> wrote:
> nos...@please.thankyou wrote:
> > functions in csh...
> I can't really say why, but yes I think it is by some uninformed
> people. I've studiously avoided learning anything about csh, only to
> have to learn it after all.
Well, just so we know that you understand that you know that we
understand....
If you _really_ have to use csh here is a kludge to simulate functions
in csh.... I did not come up with this and merely forward this information.
From: kla...@informatik.rwth-aachen.de (Klaus Frank)
Newsgroups: comp.unix.shell
Subject: Re: function in c-shell
Date: 17 Jan 2001 18:45:09 GMT
In comp.unix.shell you write:
>Can I write a function in .cshrc that can accept an argument? I yes,
>can someone give an example. I would like to be able to call the
>function in the command line at anytime I like.
Yes. It can be done with a little helper function... see usage example at
end.
!!:1 means first argument, !!:15 the fifteenth argument, !!:* all arguments.
-- Klaus Frank <kla...@Pool.Informatik.RWTH-Aachen.DE>
alias make_alias '\\
<<"end_alias" sed -e '"'"'\\
#\\!/bin/sed -f\\
#\\
## Make the eval command\\
# quote quotes\\
s/'"'"'"'"'"'"'"'"'/'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'/g;
\\
# enclose with quotes\\
1s/^/eval '"'"'"'"'"'"'"'"'/;\\
$s/$/'"'"'"'"'"'"'"'"'/;\\
#\\
## Make the alias command\\
# escape exclamation marks and newlines\\
s/\\!/\\\\!/g;\\
s/$/\\\\/g\\
# quote quotes\\
s/'"'"'"'"'"'"'"'"'/'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'/g;
\\
# enclose with quotes\\
1s/^/alias @alias_name@ '"'"'"'"'"'"'"'"'/;\\
$a\\\
;echo >/dev/null'"'"'"'"'"'"'"'"'\\
#^^^^^^^^^^^^^^^ (workaround against printing of arguments)\\
'"'"' | \\
sed -e s/@alias_name@/\!\!:1/ >/tmp/make_alias$$; \\
source /tmp/make_alias$$; \\
rm /tmp/make_alias$$; \\
'
make_alias example
echo -n 'starting command "!!:1" .....'
if ( { !!:1 } ) then
echo ok
else
echo fail
endif
"end_alias"
example true
example false
=Brian
Why are you programming in csh? Can you switch to another shell?
Read these,
http://www.grymoire.com/Unix/Csh.html
http://www.grymoire.com/Unix/CshTop10.txt
http://www.perl.com/pub/a/language/versus/csh.html
--
David Thompson
dat...@yahoo.com
--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.