7 ms·
Bash has a huge number of little shortcuts that are difficult to learn. When one encounters a sequence of symbols like $(...), it is difficult to Google for its
by amelius 9y ago
Bash has a huge number of little shortcuts that are difficult to learn. When one encounters a sequence of symbols like $(...), it is difficult to Google for its meaning. The reason shells nevertheless have these shortcuts is of course because they are shells: from the commandline it can be very convenient to use shortcuts.
But, in my opinion, that's where it should stop: one shouldn't use a shell language for scripting. In scripts, it is simpler to use more verbose and clear constructs, because most editors are very powerful and provide shortcuts themselves.
- yorwba 9y agoYeah, but why are you trying to use a search engine that cares less and less about exact matches, when there's a manual? >man bash /\$\( # search pattern needs escaping ... value is evaluated as an arithmetic expression even if the $((...)) expansion is not used (see Arithmetic Expansion below). Word split‐ ... n # go to next match Command Substitution Command substitution allows the output of a command to replace the command name. There are two forms: $(command) or `command` (detailed description follows) I'm still in favor of using more verbose and especially more clear constructs, but not because they are easier for Google, but because they ideally hold enough information on their own that you don't even need to look it up to know what it does.
- orev 9y agoMan pages are specifically reference documents, not tutorials or guidebooks. To say one should use a man page is to say that one must completely digest the entirety of the tool prior to ever actually using it. That’s just simply not feasible, nor should it be expected of anyone beyond trivial tools. Man pages simply don’t provide the context for solving a problem like a guidebook or tutorial would, which is why there are so many sites that start with a problem and then explain the tools.
- tomsmeding 9y agoWhich is why the parent advised to treat the man page like a reference document, by searching in it. Some man pages are just badly written and are indigestible even when searching for a specific thing, but in general, that approach works quite often.
- falcolas 9y agoAnd even in the worst case, the man pages give you more context to use in your subsequent web search. To use the original example, once you've identified that $(...) is Command Substitution, you have something that pulls up meaningful results in every search engine.
- hyperpape 9y agoIs there some trick to searching man pages that I don’t know? Because my usual experience is: type man foo type /-p type n n n n n n n n n as there are a bunch of matches like “...does bar when combined with -p...” A presentation of man pages that used hypertext would make me a lot happier.
- anjbe 9y agoBSD man pages (and many Linux man pages, though a minority) are written in semantic “mdoc” macros, rather than the classic “man” macros that are strictly presentational. If you’re using mandoc (http://mandoc.bsd.lv/ http://mandoc.bsd.lv/) as your man(1) program—the default on OpenBSD and a couple of Linuxes like Void and Alpine—it will use these semantics to generate hyperlinks in the terminal using more(1) and less(1)’s ctags support. So on my machine, your example becomes: type man foo type :t type p This brings me to the first instance of a command‐line flag named “-p” or environment variable named “p” in an itemized list. It translates to HTML too—check out the links generated by the web viewer, which uses the same backend. https://man.openbsd.org/ls.1 https://man.openbsd.org/ls.1
- hyperpape 9y agoThat’s awesome! I think a table of contents could be nice addition for the HTML version (at least for pages that are longer than less).
- barrkel 9y agoI generally find things easier to learn with reference documents than tutorials unless I'm unfamiliar with the problem domain and have no mental model to map things to. That's very rare these days, so reference documents are the way to go. Amusingly, reference documents are themselves increasingly rare, and what you usually get is a rough tutorial and set of examples that cover perhaps 15% of the feature set, and need to dive into the source to figure everything else out.
- gbacon 9y agoLook up the name of the concept in the manual and search for that. Compare Google or Stack Overflow searches for <() versus “process substitution.”
- AlecSchueler 9y agoIt is a reference, and searching for the pattern GP mentioned finds you references to arithmetic expression evaluation and to command substitution. Those are the terms one can Google for if further explanation is required.
- gumby 9y agoThis is why the less program has the / command — so you can search the man page for the syntax you are curious about.
- Goladus 9y agoIt's not just from the command line that these shortcuts are useful. Once you have a decent baseline on shell scripting fundamentals, the constructs are often highly optimized towards efficient and readable scripts. Not having to put every command in quotes, for example, is a huge advantage all by itself, especially if any argument lists have quoted arguments. The $(...) construct is pretty fundamental to bash scripting and should be covered in any decent tutorial.
- jelgt2011 9y agoexplainshell.com is your friend here.