${variable:-word} - If variable is not set, returns word, otherwise returns variable.
- $ variable=bob
- $ echo ${variable:-not set}
- bob
- $ unset variable
- $ echo ${variable:-not set}
- not set
- $ variable=bob
- $ echo ${variable:=not set}
- bob
- $ unset variable
- $ echo ${variable:=not set}
- not set
- $ echo ${variable}
- not set
- $ variable=bob
- $ echo ${variable:+Variable already set}
- Variable already set
- $ unset variable
- $ echo ${variable:+Variable already set}
- <this is the command returning nothing>
- $ variable=bob
- $ echo ${variable:?word}
- bob
- $ unset variable
- $ echo ${variable:?word}
- bash: variable: word
- $ variable=bob
- $ echo ${variable:?word}
- bob
- $ unset variable
- $ echo ${variable:?word}
- bash: variable: parameter null or not set
${variable:startnum} - Display variable starting at character startnum
- $ variable=1234567890
- $ echo ${variable:4}
- 567890
- $ variable=1234567890
- $ echo ${variable:4:2}
- 56
- $ variable="landing ground on island"
- $ echo ${variable#land*}
- ing ground on island
- $ variable="landing ground on island"
- $ echo ${variable##land*}
- <this is the command returning nothing>
- $ variable="landing ground on island"
- $ echo ${variable%*land}
- landing ground on is
- $ variable="landing ground on island"
- $ echo ${variable%%*land}
- <this is the command returning nothing>
- $ variable=1234554321
- $ echo ${variable/1/00}
- 00234554321
- $ variable=1234554321
- $ echo ${variable//1/00}
- 002345543200
${variable%pattern1/pattern2} - Replace pattern1 with pattern2 if variable ends with pattern1
No comments:
Post a Comment