Experimenting with scripts to perform various tasks using bash.
Helpful guides:
- Brian P. Hogan, Small, Sharp Software Tools (Pragmatic Bookshelf, 2019).
- Explanation of
xargs
: "a command line utility for building an execution pipeline from standard input. Whilst tools likegrep
can accept standard input as a parameter, many other tools cannot. Usingxargs
allows tools likeecho
andrm
andmkdir
to accept standard input as arguments." - Shell vs. R Fundamentals
Notes:
- GNU core commands (via iamlemec help):
- "The general usage of piping (
|
) should be covered in most shell tutorials though. And of course you can always look at the man page (for example, runman xargs
) for these commands." cut
: splits lines by a given delimiter and lets you select a field or fields to return. So you could make a crude CSV selector with this and -d ,, though it wouldn't handle quotes or escaping.xargs
: this is pretty handy but not obviously so at first. It'll pass a list of arguments to a given command. So in a case similar to above, instead of writingcat $(echo file.txt)
, we could writeecho file.txt | xargs cat
. For multiple arguments we could writeecho file1.txt file2.txt | xargs cat
. And if we want them run one at a time, we'd needecho file1.txt file2.txt | xargs -n 1 cat
.
- "The general usage of piping (