-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions support to tcsh #4
Comments
Although the C Shell lacks functions, aliases serve as workaround: alias function 'if -e $1 then\
echo OK\
else\
echo Not OK\
endif' Pipes and I/O redirection don't work well with multi-line aliases, except if setenv qscr 'if -e $1 then\
echo OK\
else\
echo Not OK\
endif'
mkfifo ~/qscr
alias qscr '( echo "$qscr:q" > ~/qscr & ) ; source ~/qscr' Or have it in an alias alone, with alias qscr '( echo '\''if -e $1 then\\
echo OK\\
else\\
echo Not OK\\
endif'\'' > ~/qscr & ) ; source ~/qscr'
mkfifo ~/qscr |
I always think that for functions there's programming languages like Perl, and shells should solely be for interactive purposes (what would be a difference if not). But that's my own opinion which lead me to adopt C shell rather than Bourne shell (sh, dash, ksh, bash etc) as my Unix CLI. IMHO We should not futher complicate the programming (scripting) aspect of shells but rather improve it's interactive capabilities which makes them easier for use for command typing purposes and so. |
I'm leaving another workaround here. I remember reading somewhere #!/bin/tcsh -f
alias function 'source $0 _FUNC'
if ( "$1" == "_FUNC" ) goto "$2"
set ret = "`function myfunc`"
echo "$ret"
exit
myfunc:
function myfunc2
echo "A function."
exit
myfunc2:
echo "Another function."
exit Note this only works on Tcsh. The original Csh doesn't allow for passing more than one argument. |
If you're interested, I'm working on the |
thanks. I hope you will enhance it, test it and put it into tcsh in the future. Note that the only way I've found to overcome this lack of functions in tsch is to run another tcsh script with parameters. In the end, in my scripting software, I ended up with a script that launched another script that launched another script that launched another script... and so on... In the end, I had about twenty files in my software. If there had been functions, I could have saved myself a lot of complexity. |
Yes, it does support passing parameters, @Navis-Raven. Parameters are stored to the |
it seems, and I mean it seems to me, that if this function integrates tcsh, bash will definitely be a thing of the past. I may be exaggerating a little, but this is a major breakthrough. |
As requested in tcsh-org#4, here's my proposal. This is a wrapper around goto and source. The script recurses itself and searches for a goto label. It's an error for labels not contain an exit to their end. This was tested sparsely, and may contain bugs I haven't faced, but is working as expected. One bug to be noted is that pipes don't give up on errors. This is possibly due to forking.
As requested in tcsh-org#4, here's my proposal. This is a wrapper around goto and source. The script recurses itself and searches for a goto label. It's an error for labels not contain an exit to their end. This was tested sparsely, and may contain bugs I haven't faced, but is working as expected. One bug to be noted is that pipes don't give up on errors. This is possibly due to forking.
As requested in tcsh-org#4, here's my proposal. This is a wrapper around goto and source. The script recurses itself and searches for a goto label. It's an error for labels not contain an exit to their end. Function calls outside labels are, by default, labeled main. This was tested sparsely, and may contain bugs I haven't faced, but is working as expected. One bug to be noted is that pipes don't give up on errors. This is possibly due to forking. I noticed Tcsh has a built-in function command, but I can't trace the code. Said built-in function command is evaluated before mine, thus those who attempt to execute it won't get the correct error message.
As requested in tcsh-org#4, here's my proposal. This is a wrapper around goto and source. The script recurses itself and searches for a goto label. It's an error for labels not contain an exit to their end. Function calls outside labels are, by default, labeled main. This was tested sparsely, and may contain bugs I haven't faced, but is working as expected. One bug to be noted is that pipes don't give up on errors. This is possibly due to forking. I noticed Tcsh has a built-in function command, but I can't trace the code. Said built-in function command is evaluated before mine, thus those who attempt to execute it won't get the correct error message.
As requested in tcsh-org#4, here's my proposal. This is a wrapper around goto and source. The script recurses itself and searches for a goto label. It's an error for labels not contain an exit to their end. Function calls outside labels are, by default, labeled main. This was tested sparsely, and may contain bugs I haven't faced, but is working as expected. One bug to be noted is that pipes don't give up on errors. This is possibly due to forking. I noticed Tcsh has a built-in function command, but I can't trace the code. Said built-in function command is evaluated before mine, thus those who attempt to execute it won't get the correct error message.
954cfd6 This new version relies on a tree derived from variables and aliases. Unlike to aliases and variables, the tree is restrictive. Once a function is declared, may not be redeclared or undeclared. I was afraid this wouldn't work out for some operations, such as loops and |
As requested in tcsh-org#4, here's my proposal. This is a wrapper around goto and source. The script recurses itself and searches for a goto label. It's an error for labels not contain an exit to their end. Function calls outside labels are, by default, labeled main. This was tested sparsely, and may contain bugs I haven't faced, but is working as expected. One bug to be noted is that pipes don't give up on errors. This is possibly due to forking. I noticed Tcsh has a built-in function command, but I can't trace the code. Said built-in function command is evaluated before mine, thus those who attempt to execute it won't get the correct error message.
Enhancement proposing: Add functions supporting to tcsh (like in bash, but with parameters)
like here: https://ryanstutorials.net/bash-scripting-tutorial/bash-functions.php
But It would be good if these functions in tcsh integrates parameters.
The text was updated successfully, but these errors were encountered: