-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvars.txt
24 lines (22 loc) · 1.29 KB
/
vars.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# variable substitutions Substrings
${FOO%suffix} Remove suffix ${FOO:0:3} substring (position, length)
${FOO#prefix} Remove prefix ${FOO:(-3):3} substring from the right
${FOO%%suffix} Remove long suffix Arguments:
${FOO##prefix} Remove long prefix $# number of arguments
${FOO/from/to} Replace first match $* all positional arguments as a single word
${FOO//from/to} Replace all $@ all positional arguments as separate strings
${FOO/%from/to} Replace suffix $1, $2 etc first, second, .. argument
${FOO/#from/to} Replace prefix $_ last argument of previous command
# mnemonic: suffix % comes after the $ (variable) on the keyboard,
# the prefix # before it
# Case
${FOO,} lowercase first character
${FOO,,} lowercase whole value
${FOO^} uppercase first character
${FOO^^} uppercase whole value
${FOO:-val} $FOO, or val if unset (or null)
${FOO:=val} Set $FOO to val if unset (or null)
${FOO:+val} val if $FOO is set (and not null)
${FOO:?message} Show error message and exit if $FOO is unset (or null)
# Omitting the : removes the (non)nullity checks, e.g. ${FOO-val} expands to val
# if unset otherwise $FOO.