Live data from Hacker News

The bash book to rule them all

fabiensanglard.net

21–30 of 56 posts

Re: The bash book to rule them all

#21

Earlier quoted context omitted.

Huh ? Which OS X are you on ? What you posted is not reproducable on Ventura (13.6) % uname Darwin % which cd cd: shell built-in command

Depends on your shell, if you execute `which -a cd` it will show you /usr/bin/cd in addition to the 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 )

> It's unclear to me what /usr/bin/cd actually accomplishes though, even in bash.

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...

Re: The bash book to rule them all

#22

Earlier quoted context omitted.

Because Python is godawful for dependencies. With Go, you write, you compile, you ship the binary, job done.

Is Go genuinely as dependency independent as bash on a fresh Linux install? If so I'd find this very interesting and perhaps worthwhile to learn. I work in an environment where everything is done at the Linux command line. I'd be thrilled to re-do some of my my complex bash scripts in Go if there is a good advantage to doing so .

The idea is that if you need dependencies, you only need them present during compilation on the machine you develop on. You then compile a statically linked binary and copy this to the machine where it's needed.

There may be other advantages like static types, editor integration and so on, but that's beside the point.

Re: The bash book to rule them all

#23
The title of the book (perhaps a more useful title) is

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

Re: The bash book to rule them all

#24

$ uname Darwin $ which cd /usr/bin/cd

Huh ? Which OS X are you on ? What you posted is not reproducable on Ventura (13.6) % uname Darwin % which cd cd: shell built-in command

I’m on Ventura 13.6.1. Looks like your which is a shell built-in as well. Try

  ls /usr/bin/cd

Re: The bash book to rule them all

#25
post #4

I usually recommend Data Science At The Command Line https://jeroenjanssens.com/dsatcl/ 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.

I've written books for GNU grep, sed, awk as well as one for coreutils. Free to read online. See https://github.com/learnbyexample/scripting_course#ebooks for links.

Have you looked at https://github.com/BurntSushi/xsv for csv processing?

Re: The bash book to rule them all

#26

Controversial perhaps, but I now use Go where I used to be a prolific shell script script coder. 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.

Two catches I could see:

* 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.

Re: The bash book to rule them all

#27

I believe it's been posted here before, but I also use this for reference whenever I forget the syntax to something, or know there must be a better way than what I am doing. https://github.com/dylanaraps/pure-bash-bible

Don't forget about Greg's Wiki

https://mywiki.wooledge.org/BashFAQ

(and of course we're all using ShellCheck to check our scripts for common mistakes)

Re: The bash book to rule them all

#28
Ok this may be a little over the top but in my experience there’s a better way to learn bash: implement bash. I did this for a school project, along with job control, pipes, redirects, builtins. All of the trip ups mentionned in this article will become obvious.

Re: The bash book to rule them all

#29
post #11

Controversial perhaps, but I now use Go where I used to be a prolific shell script script coder. 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.

Even more controversial, I use Swift.

Swift for system operations?

Re: The bash book to rule them all

#30

Controversial perhaps, but I now use Go where I used to be a prolific shell script script coder. 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.

I can't go along with your reasons at all (installing go on every machine is not solving a portability problem, it is the portability problem) but I'm going to leave that aside.

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.

Post reply on HN