From c2fc594db46a9c1e0c6522f394805d81ce77b7af Mon Sep 17 00:00:00 2001 From: I-Man Ng Date: Thu, 9 May 2019 15:41:47 +0800 Subject: [PATCH] Improve 'get the first character of variable Thanks to Masta's command on Reddit --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5479404..3616e2c 100644 --- a/README.md +++ b/README.md @@ -1018,9 +1018,13 @@ echo ${#var} ``` ##### get the first character of the variable ```bash -var="some string" +var=string +echo "${var:0:1}" +#s + +#or echo ${var%%"${var#?}"} -#s + ``` ##### remove the first or last string from variable ```bash