mirror of
https://github.com/onkelbeh/cheatsheets.git
synced 2026-08-16 14:04:47 +02:00
8
bash.md
8
bash.md
@@ -119,15 +119,15 @@ Parameter expansions
|
||||
name="John"
|
||||
echo ${name}
|
||||
echo ${name/J/j} #=> "john" (substitution)
|
||||
echo ${name:0:2} #=> "jo" (slicing)
|
||||
echo ${name::2} #=> "jo" (slicing)
|
||||
echo ${name::-1} #=> "joh" (slicing)
|
||||
echo ${name:0:2} #=> "Jo" (slicing)
|
||||
echo ${name::2} #=> "Jo" (slicing)
|
||||
echo ${name::-1} #=> "Joh" (slicing)
|
||||
echo ${food:-Cake} #=> $food or "Cake"
|
||||
```
|
||||
|
||||
```bash
|
||||
length=2
|
||||
echo ${name:0:length} #=> "jo"
|
||||
echo ${name:0:length} #=> "Jo"
|
||||
```
|
||||
|
||||
See: [Parameter expansion](http://wiki.bash-hackers.org/syntax/pe)
|
||||
|
||||
Reference in New Issue
Block a user