Merge pull request #1383 from zhumengu/master
This commit is contained in:
commit
ae18baa7e9
25
bash.md
25
bash.md
|
@ -138,6 +138,7 @@ See: [Parameter expansion](http://wiki.bash-hackers.org/syntax/pe)
|
||||||
STR="/path/to/foo.cpp"
|
STR="/path/to/foo.cpp"
|
||||||
echo ${STR%.cpp} # /path/to/foo
|
echo ${STR%.cpp} # /path/to/foo
|
||||||
echo ${STR%.cpp}.o # /path/to/foo.o
|
echo ${STR%.cpp}.o # /path/to/foo.o
|
||||||
|
echo ${STR%/*} # /path/to
|
||||||
|
|
||||||
echo ${STR##*.} # cpp (extension)
|
echo ${STR##*.} # cpp (extension)
|
||||||
echo ${STR##*/} # foo.cpp (basepath)
|
echo ${STR##*/} # foo.cpp (basepath)
|
||||||
|
@ -571,21 +572,25 @@ History
|
||||||
|
|
||||||
### Operations
|
### Operations
|
||||||
|
|
||||||
| `!!` | Execute last command again |
|
| Code | Description |
|
||||||
| `!!:s/<FROM>/<TO>/` | Replace first occurrence of `<FROM>` to `<TO>` in most recent command |
|
| -------------------- | --------------------------------------------------------------------- |
|
||||||
| `!!:gs/<FROM>/<TO>/` | Replace all occurrences of `<FROM>` to `<TO>` in most recent command |
|
| `!!` | Execute last command again |
|
||||||
| `!$:t` | Expand only basename from last parameter of most recent command |
|
| `!!:s/<FROM>/<TO>/` | Replace first occurrence of `<FROM>` to `<TO>` in most recent command |
|
||||||
| `!$:h` | Expand only directory from last parameter of most recent command |
|
| `!!:gs/<FROM>/<TO>/` | Replace all occurrences of `<FROM>` to `<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.
|
`!!` and `!$` can be replaced with any valid expansion.
|
||||||
|
|
||||||
### Slices
|
### Slices
|
||||||
|
|
||||||
| `!!:n` | Expand only `n`th token from most recent command (command is `0`; first argument is `1`) |
|
| Code | Description |
|
||||||
| `!^` | Expand first argument from most recent command |
|
| -------- | ---------------------------------------------------------------------------------------- |
|
||||||
| `!$` | Expand last token from most recent command |
|
| `!!:n` | Expand only `n`th token from most recent command (command is `0`; first argument is `1`) |
|
||||||
| `!!:n-m` | Expand range of tokens from most recent command |
|
| `!^` | Expand first argument from most recent command |
|
||||||
| `!!:n-$` | Expand `n`th token to last 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.
|
`!!` can be replaced with any valid expansion i.e. `!cat`, `!-2`, `!42`, etc.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue