Cshell input from bash

I have a bash script and need to run some commands in cshell inside it.

#!/bin/bash

echo entering_to_cshell
csh
echo in_cshell
exit
echo exited_from_cshell

      

Why is this script working as expected? It only prints entering_to_cshell

and doesn't exit cshell.

+3


source to share


2 answers


Using

csh

      

you start a new subshell where your script is not being executed. Therefore, none of your next commands are executed. Your script is waiting for this subshell to finish, which you have noticed will never happen.



Try

csh -c "echo in_cshell"

      

This way you are not creating a new subshell that your script is not affected by.

+2


source


By simply calling csh

the script, you will start an interactive csh session. You will notice that after exiting the session, csh

your script will continue with subsequent echoing and quiting on exit

.

To pass a sequence of commands csh

from you to a bash script, one way would be to use the Here Document syntax to redirect commands to csh

.



#!/bin/bash

echo entering_to_cshell

csh <<EOF
echo in_cshell
exit
EOF

echo exited_from_cshell

      

Lines between EOF records will be processed as script which are interpreted csh

.

0


source







All Articles