2022-10-13 19:57:22 +00:00
|
|
|
#!/bin/sh
|
|
|
|
test-colors
|
|
|
|
|
|
|
|
cat <<'EOF'
|
|
|
|
Globbing:
|
|
|
|
- ${VAR#pattern} :: delete shortest match from beginning
|
|
|
|
: file='sdf/fd' && echo ${file#sdf/}
|
|
|
|
- ${VAR##pattern} :: delete longest match from beginning
|
|
|
|
- ${VAR%pattern} :: delete shortest match from end
|
|
|
|
- ${VAR%%pattern} :: delete longest match from end
|
|
|
|
- ${VAR/search/replace} :: Regex replacement (kinda?)
|
|
|
|
Examples:
|
|
|
|
- ${VAR:*} :: retain the part before the last colon
|
|
|
|
- ${VAR##*/} :: retain the basename
|
|
|
|
- ${VAR%.*} :: remove extension
|
|
|
|
- [[https://unix.stackexchange.com/a/486694][argument from end of list]] ::
|
2023-09-11 23:16:35 +00:00
|
|
|
: eval last=\$$(($#-1))
|
2022-10-13 19:57:22 +00:00
|
|
|
(uses arithmetic substitution, a non-POSIX feature)
|
|
|
|
EOF
|