6 ms·
In other words: making bash more like zsh
by technimad 11y ago
In other words: making bash more like zsh
- jjawssd 11y agoCame here to say the exact same thing. Get zsh today. Give it a spin.
- aerique 11y agoOr fish, which is basically zsh with sane defaults.
- burke 11y agoAnd a completely incompatible non-POSIX syntax, which sounds great in theory but isn't nearly enough better to justify the departure IMHO.
- massysett 11y agoWhy does compatibility matter? If you have a script written for sh or bash it will just run using that interpreter.
- xaduha 11y agoThere are http://www.commandlinefu.com http://www.commandlinefu.com and the like. I copy and paste stuff from the web into the shell occasionally, I'm sure everyone does. I do use fish, but it is annoying sometimes, it's missing the most basic stuff like backticks. So much so that I think I'm going to stop.
- waxjar 11y agoI'm sure you know this, but it's not missing that feature. It's just that the syntax is different.
- stormbeta 11y agoFor starters, any utilities based on sourcing won't work, such as nvm/rbenv/etc. That's technically true for zsh in cases, but it's far easier to port or add compatibility for zsh than fish.
- freddie_mercury 11y agoYou can use bass which solves this problem without porting the script to fish: https://github.com/edc/bass https://github.com/edc/bass
- SoMuchToGrok 11y agoMinus it being bash-compliant. Deal breaker for most.
- coldtea 11y agoOr bash, since it will be installed everywhere, you don't have to get it, and most scripts you'll find online will work on it.
- MikeKusold 11y agoThis is a non-issue. The `!#/bin/bash` at the top of scripts will tell the interpreter which shell to run. And any one liner I've found online for bash has also worked on zsh (for me), but even if it didn't: `bash -c ls`
- aerique 11y agoYes exactly. Today I learned people actually write / use scripts without specifying the interpreter at the top of the script. This is like writing a Ruby script and expecting it to work when calling it with the Python interpreter.
- jlgaddis 11y agoYeah, it's actually not installed everywhere (e.g. FreeBSD).
- coldtea 11y agoAnywhere that matters. Besides, still more places than fish or zsh.
- wyldfire 11y agoI hear a lot about it -- could you give me your favorite 2-3 features that make you prefer it over bash?
- jjawssd 11y agoI am using zsh + prezto. https://github.com/sorin-ionescu/prezto https://github.com/sorin-ionescu/prezto Tab completion is extremely powerful. Even serious spelling mistakes are forgiven. The prompt is Git-aware and this provides a lot of helpful information which saves me from having to query the git cli. There are also plugins available for completion of other programs such as rake
- Symbiote 11y agoThree things I use regularly, even in scripts: 1) Glob qualifiers: ls *(.) will only match files, not directories, symlinks etc. ls **/*.jpg(.L-3000000on[1,5]) **/*.png(N) will match .jpg files in the current and all subdirectories, which are: . files L-3000000 with "length" (size) under 3MB on ordering them numerically [1,5] and only the first five plus any .png files, if they exist (N = it won't fail if they don't). I have some scripts with expressions this complicated, but day-to-day it's useful for finding empty files (L0) or excluding directories. "man zshexpn" and search "Glob Qualifiers". 2) Glob operators: ls DSC<100-200>.JPG matches files with names between DSC100.JPG to DSC200.JPG. setopt extended_glob ls *.java~*Test* matches all .java files, except those matching Test*. Same man page, search "Glob Operators". 3) Lazy for-loops (single command doesn't require do-done), and taking two variables: echo "A 1" > tempfile for i j in $(<tempfile); echo $i $j 4) Parameter expansion. > x=EXAMPLE.jpg > echo $x:r.png ${x:r:l}.png EXAMPLE.png example.png Interactively, shell history seems to be nicer, I use a couple of global aliases (alias -g L='| less'), and the completion system completes everything you can possibly think of, like usernames, hostnames, remote filenames, HTTP URLs, processes (for kill)...
- mryan 11y agoGreat list - I didn't know about glob operators. That glob negation is going to be very handy. Re number 2: That works in plain old Bash too: ls DSC{100..200}.jpg
- scrollaway 11y agoSpeaking of zsh, here's my zshrc file: https://github.com/jleclanche/dotfiles https://github.com/jleclanche/dotfiles Sane defaults, useful aliases, no dependencies and easy to expand upon. I made it mostly to give either a sensible default rc file to extend, or just a general high quality prompt.
- TallGuyShort 11y agoI'm a big fan of zsh. It doesn't seem to be solely focused on just "doing what you mean", which some of these tweaks seem aimed at; it seems aimed more at correctness. e.g., it would allow you to pass * .txt into a command if * .txt doesn't match anything. Bash will just assume I mean literally '* .txt' so you get different behaviour depending on whether or not there's a wildcard match. zsh has taught me the good habit of always using \* when I don't explicitly want shell expansion. edit: spaces add after asterisks to avoid formatting weirdness
- ridiculous_fish 11y agoHeh, fish shell contributors had a long discussion of failed wildcard expansions at https://github.com/fish-shell/fish-shell/issues/2394 https://github.com/fish-shell/fish-shell/issues/2394 . We all pretty much agreed that bash's passglob behavior is really bad. zsh's default is much better. Though to be fair, bash-style passglob behavior can be enabled in zsh by setting NO_NOMATCH. zsh is still zsh, after all. There's still plenty more wildcard nuttiness. A favorite is to execute a bare *: zsh will try to execute the first file, passing the other files as arguments!