r/shell • u/scroll_down0 • Jan 08 '25
Why does source in csh report "undefined variable," but works fine in zsh?
I'm having an issue with running a script using csh (specifically tcsh). When I attempt to run the script, it throws an "undefined variable" error related to the source command. However, when I run the
same command with zsh, I don't encounter any errors. Can anyone explain why this happens?
Steps to reproduce:
using tcsh;
$ cat script.csh#!/bin/tcshecho "Starting script..."source env/bin/activate.cshecho "Script completed."> echo $SHELL/bin/tcsh> ./script.cshStarting script...prompt: Undefined variable.Script completed.>
using zsh;
$ cat script2.sh#!/bin/zshecho "Starting script..."source env/bin/activateecho "Script completed."$ echo $SHELL/usr/bin/zsh$ ./script2.shStarting script...Script completed.
Why does source work in zsh but throws an "undefined variable" error in tcsh? Is there a specific difference between how source is handled in tcsh and zsh that could explain this behavior?
I appreciate any insights or suggestions to resolve this issue.
3
u/aioeu Jan 08 '25
We're not psychic. We can't see what
activate.cshcontains from here.