432
votes
Accepted
What are the practical differences between Bash and Zsh?
First, some important things:
Bash isn't going away. If you're already using bash, nothing will change for you. All that changes is that zsh will be the default login shell for new accounts, and even ...
248
votes
Accepted
ZSH: .zprofile, .zshrc, .zlogin - What goes where?
This is an attempt to write a canonical QA for this issue, as per the Meta post: Where is the list of canonical questions stored for Ask Different? I expect it to be periodically edited with the goal ...
123
votes
Accepted
zsh: bad CPU type in executable
When macOS tries to run an app that is not built for Apple silicon, macOS will prompt to install Rosetta 2 to automatically translate the app to Apple silicon.
In Terminal, there is no automatic ...
grg♦
- 206k
119
votes
Accepted
How to add permanent environment variable in zsh
Bash
Since Bash is typically the default shell you can open up this file in your home directory:
$ vim ~/.bash_profile
And add your variable to this file:
export ENV_VAR=12345
You can do this ...
47
votes
How to add permanent environment variable in zsh
First, execute in a terminal with zsh (Z Shell):
echo 'export ENV_VAR=12345' >> ~/.zshenv
Then, reload changes:
source ~/.zshenv
Finally, test if your new variable is set:
echo $ENV_VAR
...
35
votes
I switched to Catalina and enabled ZSH now my home/end key do not work in terminal
The other answers didn't work for me when connecting over SSH to the Mac. I had to add the following lines to my ~/.zshrc to get Home and End to work:
bindkey "^[[H" beginning-of-line
...
32
votes
Accepted
ZSH paste from the clipboard a command takes a few second to be write in the terminal
The final problem is related to zsh.
oh-my-zsh is executing bracketed-paste-magic, so I ended up removing it.
Because oh-my-szh doesn't have a plugin manager for this. You have to override the file: ...
27
votes
What are the practical differences between Bash and Zsh?
Change your shell now and test - no need to wait.
chsh -s /bin/zsh
All the scripts that depend on bash syntax will still find and call bash.
the same bash from Mojave is shipping on Catalina and ...
22
votes
What does the time command do on zsh Mac terminal? And what is the output of "children"?
The time you use in your question is not a command, but rather a reserved word in zsh. It can be used in two different ways and its output can be customized through the $TIMEFMT parameter. ...
21
votes
I accidentally used "touch .." , is there a way to safely delete this document?
Do not delete it! In unixish filesystems (including macOS), .. is a link to the parent directory. So if you were in the directory /Users/Serax/Desktop and you ran touch .., that's equivalent to touch /...
20
votes
Accepted
How to get rid of "You have new mail." in zsh
It tells you that you have received some mails (for example, because of your configuration of cron).
The best way is to read this mail. Type mail: at least one mail should appear. You can read by ...
19
votes
Accepted
Homebrew PATH set in .zshenv is overridden
After ~/.zshenv is sourced, the next file that is loaded is /etc/zprofile, which is provided by macOS. This script executes
eval `/usr/libexec/path_helper -s`
The manual for path_helper explains:
...
18
votes
Accepted
Cut in CLI doesn't work as expected - returns full lines every time
You can squeeze the white spaces into a single white space in ls 's output then use cut.
ls -l /usr | tr -s ' ' | cut -d ' ' -f3
but avoid parsing ls output. Here's an alternate solution.
stat -f'%...
18
votes
How do I switch tabs when using iTerm2 with Z shell
Use the keyboard shortcuts Shift + Command + ] and Shift + Command + [ to switch to next and previous tabs respectively. The same are also available under iTerm2 Menu Bar → Window menu.
The keyboard ...
18
votes
Running shell or Bash scripts with zsh on macOS v11 (Big Sur)
You only need to run chmod once for a script, not each time you run it. If you don‘t want to do this, you can also use bash ./run to execute it.
You can also create a text file with the executable bit ...
18
votes
Accepted
How to prevent accidental execution of potentially harmful commands (e.g. reboot)
Just create a reboot command in /usr/local/bin, which should come first in your $PATH.
17
votes
Accepted
How to migrate aliases from bash to zsh
If until now you've been using ~/.bash_profile for the loading the aliases, here are some of the ways you can migrate your aliases:
1. Copy the contents:
The most assiduous and obvious way is to ...
17
votes
Why can't I use zsh?
@bmike has already offered the easiest solution, but I wanted to go back to the GUI instructions not working.
I found that Apple’s instructions here can be confusing. Control-Clicking will not do ...
16
votes
How do I add a directory to PATH when using `zsh` in Sierra
In zsh, including on macOS, you should add entries to your path in your .zshrc. By default this file is read from the directory located in $ZDOTDIR which defaults to $HOME if not set.
To add an entry ...
16
votes
How do I add a directory to PATH when using `zsh` in Sierra
export
To change the path within your shell session, not system-wide, you can use the bash-style export command with zsh, as documented here.
The name of the PATH variable is case-sensitive and ...
16
votes
Accepted
Why Mac Terminal remembers two consecutive commands when they are same?
You need to add the HISTCONTROL environment variable to your .bash_profile. In your .bash_profile add the following line:
export HISTCONTROL=ignoreboth:erasedups
Close and restart your bash session ...
16
votes
ZSH paste from the clipboard a command takes a few second to be write in the terminal
In your ~/.zshrc file (create it if it's not there) you can set DISABLE_MAGIC_FUNCTIONS=true and it will disable bracketed-paste-magic which is causing this issue.
16
votes
Now that MacOS Catalina has moved to zsh, can I upgrade bash 3.2.57 with 5.0.3?
You can't easily (and shouldn't) change/upgrade /bin/bash. You can install a more recent version of bash through Homebrew though, and use the information from How to use bash as default shell to ...
15
votes
Why can't I use zsh?
Don’t use sudo directly without some additional switches - your invocation would change root’s shell, not your user account.
If your short name is mike (you can check with whoami or who am i
sudo -...
15
votes
Did the shell ( terminal ) change in Catalina?
Your shell has been changed to Zsh, which is the default for new users on Catalina (10.15) and later. To go back to the old shell (BASH), run chsh -s /bin/bash (chsh is a "Change Shell command, the -s ...
15
votes
Accepted
macOS .zsh_sessions, .zsh_history, and `setopt APPEND_HISTORY`
On macOS, /etc/zshrc contains (among other things) the following lines:
# Save command history
HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
HISTSIZE=2000
SAVEHIST=1000
This is the reason you don't need to ...
14
votes
How to make auto-complete work for AWS on ZSH?
I know this question is kinda old but there's a better answer if you're running awscli 2.1 or greater and are using oh-my-zsh. Basically, to confirm this solution run this command from your zsh shell
...
13
votes
Accepted
How to make normal command `ls` and the wildcard `*` in Zsh
The glob is expanded by the shell and the resulting arguments passed to ls as if you had written them out in full.
gradle* matches once, on gradle@7.
ls gradle@7 is run.
Since gradle@7 is a ...
grg♦
- 206k
12
votes
Cut in CLI doesn't work as expected - returns full lines every time
ls doesn't use tabs, cut doesn't work with a variable number of delimeters between fields.
ls -l /usr | awk '{print $3}'
will work, or
ls -l /usr | awk 'NR > 1 {print $3}'
if you want to skip ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
zsh × 466terminal × 248
macos × 208
command-line × 170
bash × 122
iterm × 68
homebrew × 33
path × 26
mac × 13
alias × 11
permission × 10
script × 10
python × 10
environment-variables × 9
apple-silicon × 9
keyboard × 7
applescript × 7
automator × 7
finder × 6
ssh × 6
tmux × 6
network × 5
unix × 5
launchd × 5
vi × 5