From 1b67b8f2304c1787d14bb26c817774b4b7aa2eac Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Fri, 28 Feb 2014 11:24:45 -0500 Subject: Variable substr --- bash.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index 70a3b52a..d5d08e9d 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -46,6 +46,10 @@ echo '$VARIABLE' echo ${VARIABLE/Some/A} # This will substitute the first occurance of "Some" with "A" +# Substring from a variable +echo ${VARIABLE:0:7} +# This will return only the first 7 characters of the value + # Default value for variable echo ${FOO:-"DefaultValueIfFOOIsMissingOrEmpty"} # This works for null (FOO=), empty string (FOO=""), zero (FOO=0) returns 0 -- cgit v1.2.3