Запустите tcsh с произвольным сценарием запуска

818
nispio

Я хочу создать новый экземпляр tcshи создать произвольный скрипт, и все это за один шаг. Проблема в том, что когда я использую эту -cопцию, экземпляр оболочки закрывается, как только сценарий завершен. Таким образом, в следующем тривиальном примереpushd команда завершается успешно, но затем выходы оболочки:

tcsh -c "pushd ~/some/directory/of/interest" 

Как я могу получить сценарий, который изменяет среду, а затем интерактивно работать в этой среде? Это наиболее полезно при использовании в сочетании с такими программами, как sshили screen, как показано ниже:

ssh -t user@host 'tcsh -c "source ~/test_environment.csh"' 
2

2 ответа на вопрос

4
ssnobody

Our solution will involve two steps.

  1. Pass Environment variable containing path to script you want to source to new tcsh instance.
  2. Have tcsh source the script pointed at by this environment variable

For step 1 ssh will run the command you specify in your default shell (the one in the destination server's /etc/passwd) so I'll give you several solutions for this.

  • If destination shell is sh/bash: Connect to ssh server with command: ssh -t user@host 'export SOURCESCRIPT=/tmp/tmp.sh; exec /usr/bin/tcsh'
  • If destination shell is csh/tcsh: Connect to ssh server with command: ssh -t user@host 'setenv SOURCESCRIPT /tmp/tmp.sh; exec /usr/bin/tcsh'
  • If you can modify the destination's ssh server config, add/modify AcceptEnv option in /etc/ssh/sshd_config to allow SOURCESCRIPT environment variable to be passed (e.g. AcceptEnv SOURCESCRIPT), set SOURCESCRIPT in local environment and connect with command: ssh -t -o SendEnv=SOURCESCRIPT user@host 'exec /usr/bin/tcsh'

For step 2, we modify ~/.tcshrc to add the following:

if $?SOURCESCRIPT then source $SOURCESCRIPT endif 
Это очень хороший, прямой обходной путь! Для этого необходимо предварительно изменить `~ / .tcshrc` пользователя, но в моем сценарии это не проблема. nispio 8 лет назад 0
Рад слышать, что это было успешно! Спасибо, что поймал ошибку, исправил этот знак равенства. ssnobody 8 лет назад 0
-1
Mr. Minty Fresh

Correct me if I'm wrong, but can't you use the '-m' option for tcsh to load a startup script? I just read the man page and thought that you might be able to make the '~/.tcshrc' file a symlink to another script. In case there's something screwey going on with the commands, maybe you could try the '-e' or '-m' options.

Hope this helps!

EDIT: Or maybe you could use the '-i' option for interactive in conjunction with the '-c' option :)

`~ / .tcshrc` - мой стартовый скрипт, поэтому я не могу просто заменить его символической ссылкой. Я ищу способ при желании запустить альтернативный ** скрипт запуска. nispio 8 лет назад 0

Похожие вопросы