bash 在没有root访问权限的情况下安装zsh?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15293406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install zsh without root access?
提问by Jooj
Is it possible (and how)? I really need this for several remote computers where I've got ssh access (but no root access).
是否可能(以及如何)?对于我有 ssh 访问权限(但没有 root 访问权限)的几台远程计算机,我真的需要这个。
采纳答案by pratnala
You can try the chshcommand. Are you sure zsh isn't installed on the distant computer? If not, you can do this (quoted from zsh FAQ Section 1.7)
你可以试试这个chsh命令。您确定远程计算机上没有安装 zsh 吗?如果没有,你可以这样做(引自zsh FAQ Section 1.7)
The basic idea is to use exec to replace the current shell with zsh. Often you can do this in a login file such as .profile (if your shell is sh or ksh) or .login (if it's csh). Make sure you have some way of altering the file (e.g. via FTP) before you try this as exec is often rather unforgiving.
基本思想是用exec用zsh替换当前的shell。通常,您可以在登录文件中执行此操作,例如 .profile(如果您的 shell 是 sh 或 ksh)或 .login(如果它是 csh)。在尝试之前,请确保您有某种方式来更改文件(例如,通过 FTP),因为 exec 通常是相当无情的。
If you have zsh in a subdirectory bin of your home directory, put this in .profile:
如果您的主目录的子目录 bin 中有 zsh,请将其放在 .profile 中:
[ -f $HOME/bin/zsh ] && exec $HOME/bin/zsh -l
or if your login shell is csh or tcsh, put this in .login:
或者如果您的登录 shell 是 csh 或 tcsh,请将其放在 .login 中:
if ( -f ~/bin/zsh ) exec ~/bin/zsh -l
(in each case the -l tells zsh it is a login shell).
(在每种情况下, -l 都告诉 zsh 它是一个登录 shell)。
If you want to check this works before committing yourself to it, you can make the login shell ask whether to exec zsh. The following work for Bourne-like shells:
如果您想在提交之前检查它是否有效,您可以让登录 shell 询问是否执行 zsh。以下适用于 Bourne-like shell:
[ -f $HOME/bin/zsh ] && {
echo "Type Y to run zsh: \c"
read line
[ "$line" = Y ] && exec $HOME/bin/zsh -l
}
and for C-shell-like shells:
对于类似 C-shell 的 shell:
if ( -f ~/bin/zsh ) then
echo -n "Type Y to run zsh: "
if ( "$<" == Y ) exec ~/bin/zsh -l
endif
It's not a good idea to put this (even without the -l) into .cshrc, at least without some tests on what the csh is supposed to be doing, as that will cause everyinstance of csh to turn into a zsh and will cause csh scripts (yes, unfortunately some people write these) which do not call csh -fto fail. If you want to tell xterm to run zsh, change the SHELL environment variable to the full path of zsh at the same time as you exec zsh (in fact, this is sensible for consistency even if you aren't using xterm). If you have to exec zsh from your .cshrc, a minimum safety check is if ($?prompt) exec zsh.
将它(即使没有 -l)放入 .cshrc 并不是一个好主意,至少没有对 csh 应该做什么进行一些测试,因为这将导致csh 的每个实例变成 zsh 并会导致csh 脚本(是的,不幸的是有些人写了这些)不会调用csh -f失败。如果要告诉 xterm 运行 zsh,请在执行 zsh 的同时将 SHELL 环境变量更改为 zsh 的完整路径(实际上,即使您不使用 xterm,这对于一致性也是明智的)。如果您必须从 .cshrc 执行 zsh,那么最低限度的安全检查是 if ($?prompt) exec zsh。
If you like your login shell to appear in the process list as -zsh, you can link zsh to -zsh (e.g. by ln -s ~/bin/zsh ~/bin/-zsh) and change the exec to exec -zsh. (Make sure -zsh is in your path.) This has the same effect as the -l option.
如果您希望您的登录 shell 在进程列表中显示为 -zsh,您可以将 zsh 链接到 -zsh(例如,通过 ln -s ~/bin/zsh ~/bin/-zsh)并将 exec 更改为 exec -zsh。(确保 -zsh 在您的路径中。)这与 -l 选项具有相同的效果。
Footnote: if you DO have root access, make sure zsh goes in /etc/shells on all appropriate machines, including NIS clients, or you may have problems with FTP to that machine.
脚注:如果您确实具有 root 访问权限,请确保 zsh 进入所有适当机器(包括 NIS 客户端)上的 /etc/shells,否则您可能会遇到该机器的 FTP 问题。
回答by Jens
Download zsh with:
使用以下命令下载 zsh:
wget -O zsh.tar.xz https://sourceforge.net/projects/zsh/files/latest/download
mkdir zsh && unxz zsh.tar.xz && tar -xvf zsh.tar -C zsh --strip-components 1
cd zsh
You can compile zsh yourself, for example:
你可以自己编译zsh,例如:
./configure --prefix=$HOME
make
make install
and then start it explicitly, or programmatically from your current shell's startup file (put exec $HOME/bin/zsh -lin the right spot).
然后从当前 shell 的启动文件(放在exec $HOME/bin/zsh -l正确的位置)显式或以编程方式启动它。
回答by Nicholas Smith
If the machine has zsh on it you should be fine to just execute zshon a prompt to swap, if that works you can either try chshto swap your shell (should work without root) or when you're connecting with sshput ssh -t hostname zshto start it automatically.
如果机器上有 zsh,你应该可以zsh在提示交换时执行,如果chsh可行,你可以尝试交换你的 shell(应该可以在没有 root 的情况下工作)或者当你连接到sshputssh -t hostname zsh时自动启动它。

