📜 ⬆️ ⬇️

Bash's dead, baby *. Viva zsh

I will allow myself to raise the fallen banner left over from previous speakers and continue the good work of promoting zsh to the masses. I hope after reading the topic you will also change the good old one, but, as for me, stuck in the past, bash with a more convenient and advanced zsh.
Not to be unfounded, let's try to consider this case in the context of an absolutely subjective and biased comparison bash vs. zsh
Immediately make a reservation that I am not a supporter of the console on desktops, even though I use Linux at home, the GUI is closer to a person. Therefore, the story will go about things that are more useful to the administrator than the end user, but by the way who knows.

So, typical administrator operations: navigating through the file system, copying / deleting files, viewing logs, editing configuration files, moderate use of scripts to automate repetitive operations. Um ... forgot nothing?
Let's go in order.

1. Navigation


bash:
classic for all * nix (and not even * nix) shells
user@host:/home# cd dir1/subdir1/subdir2
user@host:/home/dir1/subdir1/subdir2#


zsh:
The simplest and simplest in appearance, but at the same time my most favorite feature is the autocd telepathic mode of control , that is, switching between directories without using cd explicitly. In my experience, it is enabled by default in all default zsh configs of all distributions.
In combination with the “uncovering paths” feature (that is, when you actually remember the whole path, but you are too lazy to type, in this case, you can enter only the initial characters) it makes navigation in zsh faster and more convenient about a million times (by the most modest of my calculations)
As they say, it is better to see once.
zsh autocd
')
Speaking of navigation, you can not avoid the wrenched theme autocomplex.
Autocomplete in zsh is big and beautiful, but, to be honest, I’m not using some super-fancy stuff that is completely different from bash, since for the most part they are not intuitive. But, if we talk about the intuitive use of autocomplex when navigating through files, then zsh can boast a “menu”, which, for me, is an undoubted and big step forward compared to bash.
After all, now you can use not only Tab'om, but also arrows.
And best of all, it all works not only locally, but even on a remote host:

zsh menu
(menu function, disabled by default)

But there is an interesting way to use cd in zsh (although it would seem, why after autocd someone might need cd ...)
Suppose we have the following directory structure in the file system:
  1. / projects / project1 / src / backup
  2. / projects / project2 / src / backup

and we are in the first:
user@host:/projects/project1/src/backup# cd 1 2
user@host:/projects/project2/src/backup#


magic however ...

2. Copy / Delete files


bash:
something razatakoe
user@host:/home# rm somelogs201001{12,{14..19},25}.log
(similar to copy)
zsh:
In addition to the above option from bash, in zsh you can use the following construction:
user@host:/home# rm **/*.log
with the help of which all log files will be deleted from the current and all the underlying directories
In many cases, this feature (“Recursive Globing”) in combination with ls / mv / cp can replace and simplify scripts using find

3. View logs


bash:
user@host:/home# less /var/log/messages
zsh:
Well ... here it would be naive to expect some kind of over-breakthrough. The developers have just introduced, so to speak, “intuitive” redirection.
user@host:/home# < /var/log/messages
This uses the program from the $ PAGER variable

4. Editing configuration files


bash:
user@host:/home# vim /somedir/someconfig.ini
zsh:
The operation is trivial, but you can “save on matches” here.
You can associate files by extension. For example, associate ini files with vim
user @ host: / home # alias -s ini = vim

After that just enter the file name
user @ host: / home # /somedir/someconfig.ini

we will open it for editing.

Console home gurus use this functionality to open movies, pictures and documents, but for me this is fanaticism. I repeat once again - on the desktop taxis GUI.

5. Moderate use of scripts


Moderate, because for the most typical tasks all bicycles have already been invented long ago, and in 90% of cases a simple or difficult one-liner is enough. Let's see how the contestants behave here.
I have to use campers with bash2, bash3 and zsh for work, so you can very clearly see their behavior and, one can say, the evolution in terms of scripting capabilities.
Here's how they behave on typical tasks, such as polling hosts, generating similar entries for some tables and so forth:
bash2:
user@host:/home# for i in $(seq 1 10);do ping -c 1 192.168.0.$i;done
bash3:
user@host:/home# for i in 192.168.0.{1..10};do ping -c 1 $i;done
zsh:
user@host:/home# for i in 192.168.0.{1..10};ping -c 1 $i

In this case, zsh handles the format of a variable in a cycle more carefully, i.e. code
user@host:/home# for i in 192.168.0.{001..100};echo $i
will give exactly what is expected intuitively. bash in this case will discard the leading zeroes of the counter.

In general, scripts written in bash are 99.999% compatible with zsh (and when using any compatibility keys and 100% complete. For detailed information on percentages, please read the COMPABILITY section in mane carefully), I, for example, I found my own scripts with only one difference in terms of compatibility - in bash, the array elements are numbered from 0, and in zsh from 1, which I would attribute to plus zsh, since the script will be simpler:
bash:
for element in {0..$((${#array[@]})) - 1}
zsh:
for element in {1..$((${#array[@]}))}

Far-reaching conclusions


I did not begin here to describe the remaining 50 thousand advantages, keys, and other zsh options, because as experience shows, 90% of the capabilities of any shell are not used 99.9% of the time. In addition, they offer almost no advantages in daily work and are not so intuitive as compared to bash, while requiring thoughtful work with a file in the .zshrc area

If you do not know all the above features, then the user and the zsh functionality will be absolutely indistinguishable from bash, including all its chips, such as a recursive search. Therefore, the shell can be changed without serious consequences, and gradually master.
zsh is included in most of the full-featured Linux distributions (and also * BSD + is ported to many exotic OSs, it seems even to Windows, but I will not lie - I did not check it myself), or it is easily accessible through repositories.

Bash strikes back


Even considering and using all the above advantages of zsh, there are a couple of moments in which bash is more convenient for me:
- cdspell option, which fixes without unnecessary queries, typos in cd / ect paths on cd / etc
-in ubuntu, zsh by default cannot properly co-operate with apt, which in bash can offer uninstalled or similar packages. zsh just says "package / command not found". How to beat it, I do not know . SOLVED, see UPD



* In the original, of course, everything was completely the opposite, therefore, for the sake of cheap PR, the quote had to be nastyly misquoted

UPD
1. Thank you, thank you. Transferred a topic in Linux for all
2. My config as an example of plagiarism and the inept compilation of other people's finds
3. The riddle from the menu on the remote host was solved in the comments - of course, it could not have happened without authorization by key
4. Thank you Imposeren for solving the problem of integrating zsh and apt into ubuntu. In order for apt in zsh to offer uninstalled / similar packages, it is necessary to sort out (from the word source) the file / etc / zsh_command_not_found
5. Rethinking all the comments, rarely, but aptly updated the topic in the name of the Moon and so as not to forget

Source: https://habr.com/ru/post/82537/


All Articles