It is currently Wed, 22 Mar 2023 05:18:31 GMT



 
Author Message
 TCSH and functions
Is it possible to declare and call functions with a tcsh script?

TIA,
  MWT



 Sun, 20 Jul 2003 05:07:49 GMT   
 TCSH and functions

Something close can be accomplished with aliases.  But you'll kill
yourself debugging whitespace issues.  Use {ba,k,}sh instead.



 Sun, 20 Jul 2003 05:21:00 GMT   
 TCSH and functions
What does the man page say? (If you don't have a tcsh
man page, the man page for csh should do.) I'm much too
lazy to look up the information for you.


 Sun, 20 Jul 2003 05:31:05 GMT   
 TCSH and functions
THE MAN PAGE SAID NOTHING, THATS WHY I ASKED HERE!

There really isn't any excuse for rudeness!

Kurt J. Lanza <k...@inforonics.com> wrote in message
news:3A773299.BEEA5836@inforonics.com...



 Sun, 20 Jul 2003 06:06:52 GMT   
 TCSH and functions

If the man page doesn't mention functions, odds are
pretty good that the shell in question doesn't support
them. I say this knowing absolutely nothing about tcsh,
and never having looked at the man page for such, just
knowing in general what information is in the man pages.
As for rudeness, when you ask a question in a public
forum, you can expect all kinds of answers -- the usenet
is not known for the politeness and civility of its
participants.



 Sun, 20 Jul 2003 22:29:58 GMT   
 TCSH and functions

You can use the 'alias' command instead. But this can become difficult
if you need quotes or if/then/else/endif constructs in your "function"
body.

This has been discussed recently in this newsgroup. To summarize, you
can declare "functions" quite easily if you use a meta-alias called
"make_alias" (sorry if its definition is incomprehensible).

See usage example at the end of the article.

Klaus Frank

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



 Mon, 21 Jul 2003 20:46:47 GMT   
 
   [ 6 post ] 

Similar Threads

1. tcsh: define function-like alias

2. complete function in tcsh

3. function calls in tcsh

4. leaving tcsh's watch function ?

5. Tcsh--functions

6. Function keys under Tcsh

7. binding function keys in tcsh

8. Help to convert ksh function to tcsh or csh

9. tcsh binding of function keys

10. function, function...who's got the function?


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software