mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 01:51:38 +00:00
Merge pull request #548 from justincampbell/bash-substr
Add bash variable substring example
This commit is contained in:
commit
cd7a06f98f
@ -46,6 +46,10 @@ echo '$VARIABLE'
|
|||||||
echo ${VARIABLE/Some/A}
|
echo ${VARIABLE/Some/A}
|
||||||
# This will substitute the first occurance of "Some" with "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
|
# Default value for variable
|
||||||
echo ${FOO:-"DefaultValueIfFOOIsMissingOrEmpty"}
|
echo ${FOO:-"DefaultValueIfFOOIsMissingOrEmpty"}
|
||||||
# This works for null (FOO=), empty string (FOO=""), zero (FOO=0) returns 0
|
# This works for null (FOO=), empty string (FOO=""), zero (FOO=0) returns 0
|
||||||
|
Loading…
Reference in New Issue
Block a user