From ef9f00aa5c568af55efc14a96962bdb606e66735 Mon Sep 17 00:00:00 2001 From: zhumengu Date: Sat, 14 Mar 2020 15:08:20 +0800 Subject: [PATCH 1/2] parent directory example --- bash.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bash.md b/bash.md index 28ec038df..93c408aa4 100644 --- a/bash.md +++ b/bash.md @@ -138,6 +138,7 @@ See: [Parameter expansion](http://wiki.bash-hackers.org/syntax/pe) STR="/path/to/foo.cpp" echo ${STR%.cpp} # /path/to/foo echo ${STR%.cpp}.o # /path/to/foo.o +echo ${STR%/*} # /path/to echo ${STR##*.} # cpp (extension) echo ${STR##*/} # foo.cpp (basepath) @@ -563,7 +564,7 @@ History ### Operations -| `!!` | Execute last command again | +| `!!` | Execute last command again | | `!!:s///` | Replace first occurrence of `` to `` in most recent command | | `!!:gs///` | Replace all occurrences of `` to `` in most recent command | | `!$:t` | Expand only basename from last parameter of most recent command | From d5683a9ddfbe25a123535ce71a8ef0ebb18e2f92 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Sun, 14 Jun 2020 23:54:47 +1000 Subject: [PATCH 2/2] Update bash.md --- bash.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/bash.md b/bash.md index 93c408aa4..e22af8e51 100644 --- a/bash.md +++ b/bash.md @@ -564,21 +564,25 @@ History ### Operations -| `!!` | Execute last command again | -| `!!:s///` | Replace first occurrence of `` to `` in most recent command | -| `!!:gs///` | Replace all occurrences of `` to `` in most recent command | -| `!$:t` | Expand only basename from last parameter of most recent command | -| `!$:h` | Expand only directory from last parameter of most recent command | +| Code | Description | +| -------------------- | --------------------------------------------------------------------- | +| `!!` | Execute last command again | +| `!!:s///` | Replace first occurrence of `` to `` in most recent command | +| `!!:gs///` | Replace all occurrences of `` to `` in most recent command | +| `!$:t` | Expand only basename from last parameter of most recent command | +| `!$:h` | Expand only directory from last parameter of most recent command | `!!` and `!$` can be replaced with any valid expansion. ### Slices -| `!!:n` | Expand only `n`th token from most recent command (command is `0`; first argument is `1`) | -| `!^` | Expand first argument from most recent command | -| `!$` | Expand last token from most recent command | -| `!!:n-m` | Expand range of tokens from most recent command | -| `!!:n-$` | Expand `n`th token to last from most recent command | +| Code | Description | +| -------- | ---------------------------------------------------------------------------------------- | +| `!!:n` | Expand only `n`th token from most recent command (command is `0`; first argument is `1`) | +| `!^` | Expand first argument from most recent command | +| `!$` | Expand last token from most recent command | +| `!!:n-m` | Expand range of tokens from most recent command | +| `!!:n-$` | Expand `n`th token to last from most recent command | `!!` can be replaced with any valid expansion i.e. `!cat`, `!-2`, `!42`, etc.