C shell script wont terminated if i don't modify the shebang

Hi all, I'm new to shell script
i wrote some shell script for my colleague, everyone is fine,except on user

we are using VNC viewer to work
and there are some script start with shebang #! /bin/csh
there is an user will not terminate after running the script even if a hello world
i need to ctrl+c to stop the script manually
Below is my hello world

#! /bin/csh
echo "Hello World! \a \n"
exit 0

but if i modify the shebang to

"#! /bin/csh -f"

it works , and could be terminated normally

I google it and I know that -f means fast , it will ignore the .cshrc and .login
but I tried to remove the .cshrc in his home directory,it still wont be terminated and there's no .login in his home directory

So how can I make user can normally use my script without modify my shebang ?

Welcome to the forum.

You spoiled the shebang when you added the leading double quote, so the script will be executed with your user's default shell.
On the other hand, I can't see why the first scriptlet should not terminate on exit 0 without a <CTRL>C , be it run with csh or any other shell (although I'm definitely NOT a csh er)

The shebang was quoted, then code tags were added after the original posting, so it seems the quotes weren't removed at that time

If it weren't for the it works with -f bit, I'd be inclined to ask the person for whom it doesn't work to check his VNC client configuration.

There might be a loop caused by a system csh startup file that runs before the user's .cshrc
For debugging change the shebang to

#!/bin/csh -X
1 Like

I don't get that for a number of reasons.

  • There's nothing in the O/Ps post to suggest his echo is "looping".
  • The -X wouldn't add any debug output to the parent shell and wouldn't be needed were it so obviously looping
  • The O/P already stated that the startup scripts were removed
  • Why would the same scripts behave differently between users?

More information from the O/P needed for clarification, I would say. Such as why would you "VNC" to run a script in the first place? Really VNC or, perhaps VPN via a terminal emulator? Some terminal emulators don't close when the running command (or script) exits, by default, and might require some action on the (client) user's part.

sorry i use " " in the post is just to emphasis , not i write it in the shell script

#! /bin/csh -f

this is ok, and i run the script by just type the file name

and i also found that if i use "source filepath" and it will terminate normally
with the shebang #! /bin/csh

maybe there is some reason that the child shell is in the loop?