$ echo "${person:=nameless}"
nameless
The command under will print a “not set” message and exits if the $hostname variable will not be set or if it’s null.
$ echo "${HOSTNAME:?HOSTNAME will not be set}"
fedora
$ echo "${HOSTNAME2:?HOSTNAME2 will not be set}"
-bash: HOSTNAME2: HOSTNAME2 will not be set
You’ll be able to show the size of a variable’s worth with a command like this:
$ var="bananas"
$ echo ${#var}
7
Within the instance under, the variety of characters within the variable $title shall be displayed.
$ title="sandra"
$ echo ${#title)
6
The 2 instructions under show substrings for the required variable.
$ var="123456789"
$ echo ${var:1:3}
234
$ echo ${var:0:3}
123
Within the instance under, a substring of the $textual content variable is displayed. The 6 and 5 characterize the offset and size of the textual content to be displayed.
$ textual content="I like Linux"
echo ${textual content:7:5}
Linux
Observe that the 7th character of the string is a clean. Consider the string as beginning with character 0.
