运行程序后离开交互的shell使用 [英] after running program leave interactive shell to use

查看:181
本文介绍了运行程序后离开交互的shell使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要运行指定的参数任何程序,经过加壳然后
希望这样的外壳留下作为交互式shell以备以后使用。

I want to run any program given as argument, through shell then want that shell left as interactive shell to use later.

#!/bin/bash
bash -i <<EOF
$@
exec <> /dev/tty
EOF

但它不与zsh的工作

But it is not working with zsh

#!/bin/bash
zsh -i <<EOF
$@
exec <> /dev/tty
EOF

以及如果有人知道更多更好的方式来做到这一点
请让我知道。

as well as if somebody know more improved way to do it please let me know.

推荐答案

方法1:庆典,zsh的和其他一些贝壳阅读其名称是在文件中的 ENV 通常的RC文件后的交互命令或脚本运行前的环境变量。然而庆典只做这一点,如果援引为SH和zsh只做这一点,如果用来作为sh或ksh,这实在是太有限。

Approach 1: bash, zsh and a few other shells read a file whose name is in the ENV environment variable after the usual rc files and before the interactive commands or the script to run. However bash only does this if invoked as sh, and zsh only does this if invoked as sh or ksh, which is rather limiting.

temp_rc=$(mktemp)
cat <<'EOF' >"$temp_rc"
mycommand --option
rm -- "$0"
EOF
ENV=$temp_rc sh

方法二:使外壳读不同的rc文件,其中源通常rc文件,并包含您要运行的程序的调用。例如,对于bash:

Approach 2: make the shell read a different rc file, which sources the usual rc file and contains a call to the program you want to run. For example, for bash:

temp_rc=$(mktemp)
cat <<'EOF' >"$temp_rc"
mycommand --option
if [ -e ~/.bashrc ]; then . ~/.bashrc; fi
rm -- "$0"
EOF
bash --rcfile "$temp_rc"

有关zsh的,该文件已被名为 .zshrc ,只能指定一个不同的目录。

For zsh, the file has to be called .zshrc, you can only specify a different directory.

temp_dir=$(mktemp -d)
cat <<'EOF' >"$temp_dir/.zshrc"
mycommand --option
if [ -e ~/.zshrc ]; then . ~/.zshrc; fi
rm -- $0; rmdir ${0:h}
EOF
ZDOTDIR=$temp_dir zsh

这篇关于运行程序后离开交互的shell使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆