4 ms·
Beyond the basics, the shell features with the biggest ROI beyond the basics are to quote properly and use namerefs and arrays (esp. to return values from funct
by w10-1 3y ago
Beyond the basics, the shell features with the biggest ROI beyond the basics are to quote properly and use namerefs and arrays (esp. to return values from functions), e.g.,
# find2ra arrayName {find arguments...}
# Run find command and put results in array arrayName.
find2ra() {
# (error checking removed)
local -r f2raVar="${1}"
shift
# map find entries to ra, using char=0 as delimiter
mapfile -d $'\0' -t "$f2raVar" < <(find -dsx "${@}" -print0)
# -print0: handle paths with spaces, etc.
# -ds: For consistency, use depth-first, lexigraphic order
# -x: Avoid traversing other devices
}
# sample usage
ra=()
find2ra ra . -type f -name \*.sh
for shFile in "${ra[@]}"; do ... ; done
There are many resources for shell scripts already. A good starting-point might be to list the awesome shell-script sample sites already available.
The effort to document shell is also somewhat Pyrrhic. The benefit would be... more shell? A more modern shell?
Another goal might be to switch to a real language sooner. Go and Python are the obvious choices, but Swift and Java also support shebang's:
#!/usr/bin/env swift
#!/usr/bin/env java --source 17
Dependencies are always tricky. swift-sh allows you to declare dependencies as comments after the import:
import PromiseKit // @mxcl ~> 6.5
https://github.com/mxcl/swift-sh https://github.com/mxcl/swift-sh