The bash book to rule them all
fabiensanglard.net
fabiensanglard.net
https://mywiki.wooledge.org/BashFAQ
(and of course we're all using ShellCheck to check our scripts for common mistakes)
Not because it explains bash well, but because it fits with my data science/bioinformatics niche. It's all about these funky sort/uniq/rev/cut/uniq/awk/wc/sed patterns I use everyday fiddling with csv files.
Have you looked at https://github.com/BurntSushi/xsv for csv processing?
Might want to check 'Small, Sharp Software Tools' from The Pragmatic Programmers also. It's a great book, and comparable to the O’Reilly book.
https://pragprog.com/titles/bhcldev/small-sharp-software-too...
Because a sub-process cannot change the working directory of its parent. The shell process needs to change its own working directory. Therefore cd must be a builtin.
Although, I suppose that one might execve a cd binary, which would change directory and then in turn the cd binary would execve the shell that is specified in the $SHELL env var. That would be terribly silly though :p
Efficient Linux at the Command Line: Boost Your Command-Line Skills by Daniel J. Barrett 2022
perhaps the book should be called Efficient Bash at the Command Line: Boost Your Linux Skills. It has a little table at the end that says "if you use a different shell". Not sure if this type thing suffuses the book a tall
Main reasons:
- Fewer opportunities for foot-guns
- Ease of portability, no dependencies, e.g. no more "is jq installed ?"
- Consistent cross-platforms, e.g. no more "is this system using GNU sed ?"
- Modern stuff like crypto, and "internet stuff" is just quicker and easier to do in Go.What does this part mean?
With Go, you write, you compile, you ship the binary, job done.
There may be other advantages like static types, editor integration and so on, but that's beside the point.
* Great if you can do everything natively in Go, loses advantages and I suspect gets somewhat cumbersome if you have to shell out.
* Harder to inspect on target system. If I encounter a random shell script someone left on a server, I can read it; with a binary I'd have to hope I can find the source.
Otherwise... yeah, that seems reasonable, and if you're already good at Go, sensible.
can Go be used REPL as a shell CLI? and do everything I need to do from the CLI? because that's why I use bash for scripting. An equal amount of time I spend typing at the command line, and I one language is the language I want to use.
What a clueless reply. Complete FUD.
Yeah, you can "leave that aside" because you have no clue what you're talking about.
The ONLY place Go needs to be installed is on the developer's machine.
With Go you write, you compile/cross-compile and SHIP THE COMPILED BINARY job done.
Do some homework next time before engaging in completely unfounded FUD.
Literally five seconds on Google could have shown the guy he was completely wrong.
But no, instead he posts unfounded FUD about how he will courteously "leave aside" the demonstrably INCORRECT claim that Go runtime needs to be installed on all machines that a Go program runs on.
So don't give me a hard time about it when it was that poster who made the original arrogant comment.
So it is easy to make changes by system admins/non-developers. Scripting is for glue functionality after all…
You can also use env-vars and flags in Go.
Which many would argue leads to more robust "admin glue functionality", because the admin controls how much non-admins can mess around with instead of allowing them to mess around with the core shell-script functionality.
in corporate environments, it is not easy to (nor should it be) to require every desk to install Go. If you are hired to script something (and scripts are even more important in corporate environments) and require a new piece of software to be installed, and a new language for staff to maintain, it's imposing a great burden and could very well be rejected.
I don't not know what I'm talking about, and I'm not trying to FUD, I'm trying to suggest "gird your loins". But also, I said that was not the point of my comment, I just didn't want you to think that through my silence I had accepted your earlier suggestion.
I'd say the most portable thing you can build with that's script-y enough to be pleasant is likely Ruby. If you can avoid using things introduced with Ruby 3, keep in mind platform differences and the abstractions Ruby has built-in to deal with them, and stick with stdlib, it will likely run on just about every machine with just about any Ruby.
Otherwise maybe perl?
bash used to be "a shell" and "the shell" before graphical shells became the norm. Now bash is a REPL and programming language, and you need to run an "ANSI terminal shell" to access it :)
1. the command line has a syntax of it's own ("readline", generally standard across different shells, in this instance enforced by bash) and then
2. bash has its own language you can use, turing complete, with if-branches and loops, functions, some return values, global values (env) but also file i/o can be used as up-down argument passing, i/o and you can call readline over and over
3. there are certain conventions for "filters" that fit into the above framework, and they impose a small variety of contentions onto the command lines which nest within readline syntax.
it has warts, and I really wish there was a general desire to fix them, but I guess I'm going to have to want it enough to do it myself because i've had the same ideas for 30 yrs now and nothings been happening :(
last point, people aren't picking up on the importance some of us place on a language which can script that is the same language that is the command line. We don't want two languages, we want one. i.e. a language with a REPL
And so bash exists in the context of an entire unix-y system. You can fix it for yourself, but that's not going to fix the problems that bash has. No standard library. You need to build on an abstraction that you control, that can accommodate for the differences between systems. And if you want a language with a REPL, it already exists. Ruby. You can do amazing things with Pry, Ruby's true REPL, and inline Bundler. Automatic dependency management in a single-file script? Yes please! Could also do Smalltalk or a Lisp if that way of working entices.
You literally never have to touch bash/zsh/fish/whatever if you don't want to. Set your shell to Pry. In a Ruby process you can abstract over literally everything. You can use Pry's shell-integration to do bash-y stuff or you can use editor integration to open up classes or methods in emacsclient or what have you. An actual, honest-to-god, real language, specifically engineered to be human-friendly, with everything you could ever need. It can even run it's own readline, which you can modify if you feel the need.
$ uname
Darwin
$ which cd
/usr/bin/cdWhat you posted is not reproducable on Ventura (13.6)
% uname
Darwin
% which cd
cd: shell built-in command(zsh has which as a built in command, apparently bash doesn't, which causes the different output). It's unclear to me what /usr/bin/cd actually accomplishes though, even in bash.
(final edit I hope, I found an explanation of sorts for /usr/bin/cd: https://unix.stackexchange.com/a/50060)
Seems to be something they adopted from FreeBSD if the comment in the script is anything to go by ? (`/usr/bin/cd` is a shell script, you can cat it).
It seems something to do with it being a POSIX system if this SO answer[1] is anything to go by.
Beyond my paygrade though, and given Apple's shell appears to default to the built-in it seems I don't need to care either. :-)
[1] https://unix.stackexchange.com/questions/50022/why-cant-i-re...
ls /usr/bin/cdI think the pretty animal illustrations is what initially caught my attention and helped me discover O’Reilly as a publisher to pay specific attention to in IT books. The animals trick you into opening their books, and the texts usually have you continue reading.