Home » Questions » Computers [ Ask a new question ]

invoke zsh, having it run a command, and then enter interactive mode instead of exiting

invoke zsh, having it run a command, and then enter interactive mode instead of exiting

i'd like to start zsh similar to

Asked by: Guest | Views: 32
Total answers/comments: 2
Guest [Entry]

"Not that I would advise doing this.

(sirius)~: zsh -c 'print hello; zsh -i'
hello
(sirius)~: echo $SHLVL
2

There are other tricks you can play with screen and using the $STY variable.

If you want something run from zsh with individual screens, you can check the $STY variable within your .zshrc or .zlogin. It is in the format <PID>.<TTY>.<HOSTNAME>.

if [[ -n $STY ]] then
if [[ -f ~/.zsh-$STY[(ws:.:)2] ]] then
. ~/.zsh-$STY[(ws:.:)2]
fi
fi

If in screen, and if ~/.zsh-<TTY> (from the $STY variable) exists, source that, then continue on your merry way. You can also set an environment variable before calling the interactive shell.

> FOO=bar zsh -i
> env | grep FOO
FOO=bar

> RUNTHISCOMMAND=/path/to/script zsh -i
.zshrc:
if [[ -n $RUNTHISCOMMAND ]] then
$RUNTHISCOMMAND
fi

Add those checks into your .zshrc/.zlogin."
Guest [Entry]

"I have eval ""$RUN"" at the end of my .zshrc. I can now run commands without the extra shell, with:

RUN='my_prog opt1 opt2' zsh"