bash 如何让 zsh 在 Mac OS X(在 iTerm 中)上作为登录 shell 运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1276703/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 18:24:39  来源:igfitidea点击:

How to make zsh run as a login shell on Mac OS X (in iTerm)?

macosbashshellzsh

提问by Ivan Tarasov

When zsh is set as a login shell on Mac OS X, when it is started by iTerm, zsh doesn't consider that it's being run as a login shell, although it's started as ‘-zsh' (‘-' is put as the first character of arg[0]) which is supposed to mean that it should start as a login shell.

当在 Mac OS X 上将 zsh 设置为登录 shell 时,当它由 iTerm 启动时,zsh 并不认为它是作为登录 shell 运行的,尽管它是作为“-zsh”启动的(“-”作为arg[0]) 的第一个字符,这意味着它应该作为登录 shell 启动。

So, when I set the login shell to bash, bash recognizes this first ‘-' in $0 and runs as a login shell, but zsh doesn't, although it seems that it should.

因此,当我将登录 shell 设置为 bash 时,bash 会识别 $0 中的第一个“-”并作为登录 shell 运行,但 zsh 不会,尽管它似乎应该这样做。

Is there a way to either make zsh recognize the ‘-' in the arg[0], or make iTerm run the shell with a --login command line argument?

有没有办法让 zsh 识别 arg[0] 中的“-”,或者让 iTerm 使用 --login 命令行参数运行 shell?

采纳答案by Harold Putman

In iTerm -> Preferences -> Profiles Tab -> General section set Command to: /bin/zsh --login

在 iTerm -> Preferences -> Profiles Tab -> General 部分将 Command 设置为:/bin/zsh --login

/bin/zsh --login

/bin/zsh --login

回答by Damien Wilson

chsh -s $(which zsh)

You'll be prompted for your password, but once you update your settings any new iTerm/Terminal sessions you start on that machine will default to zsh.

系统会提示您输入密码,但是一旦您更新设置,您在该机器上启动的任何新 iTerm/终端会话都将默认为 zsh。

回答by Arunkumar

Go to the Users & Groupspane of the System Preferences-> Select the User -> Click the lock to make changes(bottom left corner) -> right click the current user select Advanced options...-> Select the Login Shell:/bin/zsh and OK

转到系统首选项用户和组窗格-> 选择用户 ->单击锁进行更改(左下角) -> 右键单击​​当前用户选择高级选项...-> 选择登录外壳:/ bin/zsh 和OK

回答by hasanain

The command to change the shell at startup is chsh -s <path_to_shell>. The default shells in mac OS X are installed inside the bindirectory so if you want to change to the default zshthen you would use the following

在启动时更改 shell 的命令是chsh -s <path_to_shell>. mac OS X 中的默认 shell 安装在bin目录中,因此如果您想更改为默认值,zsh则可以使用以下命令

chsh -s /bin/zsh

If you're using different version of zshthen you might have to add that version to /etc/shellsto avoid the nonstandard shell message. For example if you want home-brew's version of zshthen you have to add /usr/local/bin/zshto the aforementioned file which you can do in one command sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells"and then run

如果您使用的是不同版本,zsh那么您可能必须添加该版本/etc/shells以避免非标准 shell 消息。例如,如果您想要 home-brew 的版本,zsh那么您必须添加/usr/local/bin/zsh到上述文件中,您可以在一个命令中执行该文件,sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells"然后运行

chsh -s /usr/local/bin/zsh

Or if you want to do the whole thing in one command just copy and paste this if you have zsh already installed

或者,如果您想在一个命令中完成整个操作,只需复制并粘贴此命令(如果您已经安装了 zsh)

sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells" && chsh -s /usr/local/bin/zsh

回答by Brian Agnew

Have you tried editing the shell entry in account settings.

您是否尝试过在帐户设置中编辑 shell 条目。

Go to the Accounts preferences, unlock, and right-click on your user account for the Advanced Settingsdialog. Your shell should be /bin/zsh, and you can edit that invocation appropriately (i.e. add the --login argument).

转到“帐户”首选项,解锁并右键单击“高级设置”对话框的用户帐户。您的 shell 应该是 /bin/zsh,您可以适当地编辑该调用(即添加 --login 参数)。

回答by Robin Klose

Use the loginutility to create a login shell. Assume that the user you want to log in has the username Aliceand that zsh is installed in /opt/local/bin/zsh(e.g., a more recent version installed via MacPorts). In iTerm 2, go to Preferences, Profiles, select the profile that you want to set up, and enter in Command:

使用该login实用程序创建登录 shell。假设您要登录的用户的用户名为Alice,并且安装了 zsh /opt/local/bin/zsh(例如,通过 MacPorts 安装了更新的版本)。在 iTerm 2 中,转到 Preferences、Profiles,选择要设置的配置文件,然后在Command 中输入:

login -pfq Alice /opt/local/bin/zsh

See man loginfor more details on the options.

有关man login选项的更多详细信息,请参阅。