Merge pull request #952 from hrvoj3e/patch-1

slicing from right
This commit is contained in:
Rico Sta. Cruz 2018-12-25 20:34:48 +08:00 committed by GitHub
commit 4eacb18b60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -3,7 +3,7 @@ title: Bash scripting
category: CLI
layout: 2017/sheet
tags: [Featured]
updated: 2018-11-19
updated: 2018-12-25
keywords:
- Variables
- Functions
@ -122,6 +122,8 @@ echo ${name/J/j} #=> "john" (substitution)
echo ${name:0:2} #=> "Jo" (slicing)
echo ${name::2} #=> "Jo" (slicing)
echo ${name::-1} #=> "Joh" (slicing)
echo ${name:(-1)} #=> "n" (slicing from right)
echo ${name:(-2):1} #=> "h" (slicing from right)
echo ${food:-Cake} #=> $food or "Cake"
```