[Tcsh] Compliments to the developers and contributors.
M G P
tateusg at hotmail.com
Mon Jul 3 00:21:24 UTC 2023
https://github.com/Krush206/3bsd-csh/commit/b8c675e
Fixed pipes and I/O redirections for the 'function' built-in.
________________________________
https://github.com/Krush206/3bsd-csh/commit/726de5d
I wanted to diverge the 'function' built-in from 'goto', so I applied a limitation so that labels must have an 'exit' to their end.
________________________________
https://github.com/Krush206/3bsd-csh/commit/7105416
Fixed the variables bug. Now is possible to modify variables globally.
________________________________
https://github.com/Krush206/3bsd-csh/commit/0d7bb67
I made it. I didn't test thoroughly, but I can tell it's limited. It doesn't work well off sub-shells. Variables defined in function calls are visible only to the called function (this resembles C in some way).
In the meantime, I'll figure out how to solve the bugs. That's what I have for now.
Contributions are welcome!
________________________________
I love how I found this workaround. C is resembled a lot more this way.
Passing variables by value is achieved by sourcing from a sub-shell. Passing variables by reference is achieved by sourcing from the parent Shell. Command substitutions always pass variables by value, though.
I'm thinking of introducing a built-in 'function' command based on this idea. Any thoughts on that?
By the way, regarding the exit status issue I reported on Csh, it was a problem on my side. My mistake. Sorry about that.
________________________________
Here's a better workaround I found to simulate functions:
if !( "$?0" ) then
echo 'You must run this script by explicitly calling its file.'
exit -1
endif
alias function 'set argv = ( \!* ) ; source "$0"'
if ( "$?main" ) goto "$1"
set main
set ret = "`function myfunc`"
echo "$ret"
exit
myfunc:
( function myfunc2 )
echo "A function."
exit
myfunc2:
echo "Another function."
exit
This is much better than aliases in scripts. Works for Tcsh and Csh.
One problem I found on Csh is the exit status output is never stored to the parent Shell.
For the function workaround described above, the workaround to store the exit status is to echo:
if !( "$?0" ) then
echo 'You must run this script by explicitly calling its file.'
exit -1
endif
alias function 'set argv = ( \!* ) ; source "$0"'
if ( "$?main" ) goto "$1"
set main
set ret = "`function myfunc "\""$1"\"" && echo 1 || echo 0`"
if ( $ret[$#ret] ) then
while ( $#ret > 1 )
echo "$ret[1]"
shift ret
end
endif
exit
myfunc:
if ( -f "$2" ) then
echo 'OK.'
echo 'File found.'
exit
endif
exit -1
________________________________
https://en.wikipedia.org/wiki/Special:MobileDiff/1102822365<https://en.m.wikipedia.org/wiki/Special:MobileDiff/1102822365>
Why do they think multi-line aliases aren't possible?
alias function 'if -e \!$ then\
echo OK\
else\
echo Not OK\
endif'
function dir
I can also make it into a variable:
set function = 'if -e \!$ then\
echo OK\
else\
echo Not OK\
endif\
:'
eval $function:q dir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.astron.com/pipermail/tcsh/attachments/20230703/5366cbdc/attachment.htm>
More information about the Tcsh
mailing list