I'd like to have tcsh start a login shell and execute a command.
I tried this:
tcsh -l -c ls
But got this error message:
Unknown option: `-l'
Usage: tcsh [ -bcdefilmnqstvVxX ] [ argument ... ].
This doc corrected my understanding; -l can only be used if it's the only argument. But, said doc also indicated that specifying '-' would work, but that resulted in a different error:
> tcsh - -c ls
-: No such file or directory.
Any suggestions?
You're misunderstanding what it says about -, although I admit that the wording is confusing. It says that argument 0 has to be -. Argument 0 is the name of the program itself, not the arguments after the command on the command line.
The way it actually works is if argv[0] begins with -, it runs as a login shell. Checking the first character of argv[0] is how shells normally detect that they're being run during a login. This is because when you login for real, the system executes your login shell with no arguments, but adds a - prefix before the shell name. You can see this in ps, you'll often see commands like -tcsh and -bash -- those are login shells.
As suggested in the comments, you can do what you want by piping the command to the shell's standard input:
echo ls | tcsh -l
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With