Functions in C-shell

Functions in C-shell

Post by Shailesh Kuma » Tue, 12 Jun 2001 15:55:34



I need to write functions in my c-shell scripts. How do I do this?

--
Shailesh Kumar

 
 
 

Functions in C-shell

Post by Cyrille Lefevr » Fri, 15 Jun 2001 20:05:13



> I need to write functions in my c-shell scripts. How do I do this?

csh only have aliases and don't have functions.

also, read the following document :

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

Cyrille.
--


Supprimer "%no-spam" et ".invalid" pour me repondre. | about who it chooses
Remove "%no-spam" and ".invalid" to answer me back.  | to be friends with.

 
 
 

Functions in C-shell

Post by Mathew Kirsc » Sat, 16 Jun 2001 00:10:19



> I need to write functions in my c-shell scripts. How do I do this?

Don't write csh scripts.
 
 
 

Functions in C-shell

Post by Keith Thompso » Mon, 18 Jun 2001 08:58:29



> I need to write functions in my c-shell scripts. How do I do this?

Basically, you don't.

You can implement each function as a separate script.

If you're really *ic, you can implement a call stack using an
array variable and explicitly push and pop any arguments and return
addresses (a return address can be implemented as a string
representing a label, a return statement as something like

    eval `goto $stack[$tos]`

But if you're a good enough programmer to get an ugly kludge like that
to work (meanwhile earning the contempt of anyone who has to maintain
your code), you're more than good enough to learn a scripting language
that does support functions (sh, bash, awk, Perl).

--

San Diego Supercomputer Center           <*>  <http://www.veryComputer.com/~kst>
Cxiuj via bazo apartenas ni.

 
 
 

Functions in C-shell

Post by Klaus Fran » Sat, 23 Jun 2001 22:49:44



>I need to write functions in my c-shell scripts. How do I do this?

It can be done with a little helper function... see usage example at end.
!!:1 means first argument, !!:15 the fif*th argument, !!:* all arguments.


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\\

$a\\\
;echo >/dev/null'"'"'"'"'"'"'"'"'\\
#^^^^^^^^^^^^^^^ (workaround against printing of arguments)\\
'"'"' | \\

    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

 
 
 

1. function in c-shell

Hi

RE: C-Shell

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.

Has anyone got a softcopy of c-shell programming tutorial preferably in
pdf format that they can email to me?

Thanks

Sent via Deja.com
http://www.deja.com/

2. Linksys combo EthernetCard

3. Functions and "ed" in a C-Shell Script.

4. make config complains

5. Changing from the Bourne shell to C-shell

6. inetd: which port?

7. C-shell on System V shell

8. IT REALLY WORKS

9. Bourne Shell vs C-Shell

10. c-shell script won't run from korn-shell / SETUID

11. Korn shell vs C-shell

12. Process history under C-shell and Bourne shell

13. conditions for C-Shell to be login shell