From b5cdd0f700912e6847441cacdbc05fd84771193f Mon Sep 17 00:00:00 2001 From: Scott Griffin Date: Tue, 23 Jun 2015 23:00:16 -0700 Subject: [PATCH 01/10] brace expansion example. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0b7ef27..b484543 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,10 @@ Notes: - In Bash, note there are lots of kinds of variable expansion. Checking a variable exists: `${name:?error message}`. For example, if a Bash script requires a single argument, just write `input_file=${1:?usage: $0 input_file}`. Arithmetic expansion: `i=$(( (i + 1) % 5 ))`. Sequences: `{1..10}`. Trimming of strings: `${var%suffix}` and `${var#prefix}`. For example if `var=foo.pdf`, then `echo ${var%.pdf}.txt` prints `foo.txt`. +- Shell brace expansion can help reduce having to re-type similar text. The command `echo foo{,bar,baz}` will expand to +`echo foo foobar foobaz`. This is helpful when copying/renaming files such as `cp somefile{,.bak}` which expands to +`cp somefile somefile.bak` or `mv some_{,absurdly_long_}filename` which expands to `mv some_filename some_absurdly_long_filename` + - The output of a command can be treated like a file via `<(some command)`. For example, compare local `/etc/hosts` with a remote one: ```sh diff /etc/hosts <(ssh somehost cat /etc/hosts) From 24c17d60743316fc4d7453139cedca2443030b3e Mon Sep 17 00:00:00 2001 From: Marcel Steinbeck Date: Sat, 27 Jun 2015 09:30:34 +0200 Subject: [PATCH 02/10] added apg, closes #101 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8d9563f..ae0c127 100644 --- a/README.md +++ b/README.md @@ -433,6 +433,8 @@ A few examples of piecing together commands: - `fortune`, `ddate`, and `sl`: um, well, it depends on whether you consider steam locomotives and Zippy quotations "useful" +- `apg`: generates several random passwords. + ## More resources From a5f64eb5f28e24bd8261598aab4ec6a945266af9 Mon Sep 17 00:00:00 2001 From: aneasystone Date: Wed, 5 Aug 2015 15:12:11 +0800 Subject: [PATCH 03/10] Use `Tab` to list available commands --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a41294..32b7045 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Notes: ## Everyday use -- In Bash, use **Tab** to complete arguments and **ctrl-r** to search through command history. +- In Bash, use **Tab** to complete arguments or list all available commands and **ctrl-r** to search through command history. - In Bash, use **ctrl-w** to delete the last word, and **ctrl-u** to delete all the way back to the start of the line. Use **alt-b** and **alt-f** to move by word, **ctrl-a** to move cursor to beginning of line, **ctrl-e** to move cursor to end of line, **ctrl-k** to kill to the end of the line, **ctrl-l** to clear the screen. See `man readline` for all the default keybindings in Bash. There are a lot. For example **alt-.** cycles through previous arguments, and **alt-*** expands a glob. From 93746b409e839f39581f397b00422e5b76853b07 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Mon, 10 Aug 2015 20:47:10 -0700 Subject: [PATCH 04/10] Link on filenames handling. Thanks to @mator. Fixes #71. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ac3b60..10ea84e 100644 --- a/README.md +++ b/README.md @@ -475,7 +475,8 @@ These are items relevant *only* on MacOS. - [awesome-shell](https://github.com/alebcay/awesome-shell): A curated list of shell tools and resources. - [Strict mode](http://redsymbol.net/articles/unofficial-bash-strict-mode/) for writing better shell scripts. -- [shellcheck](https://github.com/koalaman/shellcheck) - A shell script static analysis tool. Essentially, lint for bash/sh/zsh. +- [shellcheck](https://github.com/koalaman/shellcheck): A shell script static analysis tool. Essentially, lint for bash/sh/zsh. +- [Filenames and Pathnames in Shell](http://www.dwheeler.com/essays/filenames-in-shell.html): The sadly complex minutiae on how to handle filenames correctly in shell scripts. ## Disclaimer From f7755ef0d20112be07ad289025b42b83f7067a6b Mon Sep 17 00:00:00 2001 From: Uggla Date: Tue, 11 Aug 2015 13:30:24 +0200 Subject: [PATCH 05/10] Add vimdiff and sdiff command. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 10ea84e..8d0b553 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,9 @@ Notes: - If you ever need to write a tab literal in a command line in Bash (e.g. for the -t argument to sort), press **ctrl-v** **[Tab]** or write `$'\t'` (the latter is better as you can copy/paste it). -- The standard tools for patching source code are `diff` and `patch`. See also `diffstat` for summary statistics of a diff. Note `diff -r` works for entire directories. Use `diff -r tree1 tree2 | diffstat` for a summary of changes. +- The standard tools for patching source code are `diff` and `patch`. See also `diffstat` for summary statistics of a diff and `sdiff` easier to read diff. Note `diff -r` works for entire directories. Use `diff -r tree1 tree2 | diffstat` for a summary of changes. + +- Use `vimdiff` to compare and edit files. Really efficient ! - For binary files, use `hd` for simple hex dumps and `bvi` for binary editing. From 11bbb2bb9d1412b4971b784cba59f7da54977ebd Mon Sep 17 00:00:00 2001 From: Uggla Date: Tue, 11 Aug 2015 13:54:12 +0200 Subject: [PATCH 06/10] Fix for #146. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10ea84e..5e21d46 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Notes: - Learn about redirection of output and input using `>` and `<` and pipes using `|`. Know `>` overwrites the output file and `>>` appends. Learn about stdout and stderr. -- Learn about file glob expansion with `*` (and perhaps `?` and `{`...`}`) and quoting and the difference between double `"` and single `'` quotes. (See more on variable expansion below.) +- Learn about file glob expansion with `*` (and perhaps `?` and `[`...`]`) and quoting and the difference between double `"` and single `'` quotes. (See more on variable expansion below.) - Be familiar with Bash job management: `&`, **ctrl-z**, **ctrl-c**, `jobs`, `fg`, `bg`, `kill`, etc. From 4e794ecfde83b535b6871a449e34b07d89be2c60 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Tue, 11 Aug 2015 10:14:34 -0700 Subject: [PATCH 07/10] More on brace expansion. Updates #116. Thanks also to the suggestion in #1. --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 14126b9..1979b8f 100644 --- a/README.md +++ b/README.md @@ -115,9 +115,8 @@ Notes: - In Bash, note there are lots of kinds of variable expansion. Checking a variable exists: `${name:?error message}`. For example, if a Bash script requires a single argument, just write `input_file=${1:?usage: $0 input_file}`. Arithmetic expansion: `i=$(( (i + 1) % 5 ))`. Sequences: `{1..10}`. Trimming of strings: `${var%suffix}` and `${var#prefix}`. For example if `var=foo.pdf`, then `echo ${var%.pdf}.txt` prints `foo.txt`. -- Shell brace expansion can help reduce having to re-type similar text. The command `echo foo{,bar,baz}` will expand to -`echo foo foobar foobaz`. This is helpful when copying/renaming files such as `cp somefile{,.bak}` which expands to -`cp somefile somefile.bak` or `mv some_{,absurdly_long_}filename` which expands to `mv some_filename some_absurdly_long_filename` +- Brace expansion using `{`...`}` can reduce having to re-type similar text and automate combinations of items. This is helpful in examples like `mv foo.{txt,pdf} some-dir` (which moves both files), `cp somefile{,.bak}` (which expands to +`cp somefile somefile.bak`) or `mkdir -p test-{a,b,c}/subtest-{1,2,3}` (which expands all possible combinations and creates a directory tree). - The output of a command can be treated like a file via `<(some command)`. For example, compare local `/etc/hosts` with a remote one: ```sh From f800f02ba004e1826005b463d6de45578d399396 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Tue, 11 Aug 2015 10:17:40 -0700 Subject: [PATCH 08/10] Edits to #259 for brevity. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 540c9a5..74cc63e 100644 --- a/README.md +++ b/README.md @@ -210,9 +210,7 @@ Notes: - If you ever need to write a tab literal in a command line in Bash (e.g. for the -t argument to sort), press **ctrl-v** **[Tab]** or write `$'\t'` (the latter is better as you can copy/paste it). -- The standard tools for patching source code are `diff` and `patch`. See also `diffstat` for summary statistics of a diff and `sdiff` easier to read diff. Note `diff -r` works for entire directories. Use `diff -r tree1 tree2 | diffstat` for a summary of changes. - -- Use `vimdiff` to compare and edit files. Really efficient ! +- The standard tools for patching source code are `diff` and `patch`. See also `diffstat` for summary statistics of a diff and `sdiff` for a side-by-side diff. Note `diff -r` works for entire directories. Use `diff -r tree1 tree2 | diffstat` for a summary of changes. Use `vimdiff` to compare and edit files. - For binary files, use `hd` for simple hex dumps and `bvi` for binary editing. From 54878c375bb556feebb330ba51947becf6b4e1d7 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Tue, 11 Aug 2015 23:37:21 -0700 Subject: [PATCH 09/10] Open command in editor. Thanks to #253. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0958f9e..6b76a5b 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,10 @@ Notes: - In Bash, use **ctrl-w** to delete the last word, and **ctrl-u** to delete all the way back to the start of the line. Use **alt-b** and **alt-f** to move by word, **ctrl-a** to move cursor to beginning of line, **ctrl-e** to move cursor to end of line, **ctrl-k** to kill to the end of the line, **ctrl-l** to clear the screen. See `man readline` for all the default keybindings in Bash. There are a lot. For example **alt-.** cycles through previous arguments, and **alt-*** expands a glob. -- Alternatively, if you love vi-style key-bindings, use `set -o vi`. + +- Alternatively, if you love vi-style key-bindings, use `set -o vi` (and `set -o emacs` to put it back). + +- For editing long commands, after setting your editor (for example `export EDITOR=vim`), **ctrl-x** **ctrl-e** will open the current command in an editor for multi-line editing. Or in vi style, **escape-v**. - To see recent commands, `history`. There are also many abbreviations such as `!$` (last argument) and `!!` last command, though these are often easily replaced with **ctrl-r** and **alt-.**. From 5fef2d2bf64ffc9475d2bee035ab242d48e3f7c2 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Tue, 11 Aug 2015 23:46:17 -0700 Subject: [PATCH 10/10] Tweaks to #132. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67fbf47..9b854a4 100644 --- a/README.md +++ b/README.md @@ -395,6 +395,8 @@ A few examples of piecing together commands: - `units`: unit conversions and calculations; converts furlongs per fortnight to twips per blink (see also `/usr/share/units/definitions.units`) +- `apg`: generates random passwords + - `7z`: high-ratio file compression - `ldd`: dynamic library info @@ -459,8 +461,6 @@ A few examples of piecing together commands: - `fortune`, `ddate`, and `sl`: um, well, it depends on whether you consider steam locomotives and Zippy quotations "useful" -- `apg`: generates several random passwords. - ## MacOS X only