dash/ash
dash/ash
Posted Oct 1, 2014 22:36 UTC (Wed) by Jandar (subscriber, #85683)In reply to: dash/ash by wahern
Parent article: Bash gets shellshocked
One global array is hardly a replacement for the bash arrays. Btw the set builtin is well-known.
> A more common method is using read(1).
Do you mean managing arrays in multiple tempfiles and reading (+ writing with ugly escapes) on any usage? Appalling.
The omission of arrays in posix-shell is the major reason for me to ignore it and use bash.
Posted Oct 2, 2014 14:23 UTC (Thu)
by nix (subscriber, #2304)
[Link] (3 responses)
Posted Oct 3, 2014 9:48 UTC (Fri)
by Jandar (subscriber, #85683)
[Link] (2 responses)
typeset -a Options Files
How do you prepare (with correct quoting) a dynamic argument-vector without arrays? All other methods are ugly and error-prone beyond any acceptable limit.
Posted Oct 17, 2014 11:12 UTC (Fri)
by mgedmin (subscriber, #34497)
[Link] (1 responses)
paths[${#paths[*]}]="$1"
Rewriting this to use +=() will make my scripts a bit saner.
Posted Oct 17, 2014 12:02 UTC (Fri)
by mathstuf (subscriber, #69389)
[Link]
Posted Oct 3, 2014 19:30 UTC (Fri)
by wahern (subscriber, #37304)
[Link]
foo() {
printf "$# -> $*\n"
printf "$# -> $*\n"
Also, per POSIX: "Positional parameters are initially assigned when the shell is invoked (see sh), temporarily replaced when a shell function is invoked (see Function Definition Command), and can be reassigned with the set special built-in command."
Obviously this isn't a complete substitute for arrays, neither alone nor in tandem with other alternatives.
But my point is that people use Bash features without understanding the alternatives, and without appreciating the cost of Bash. Bash is a great interactive shell. But if you're serious about shell programming, one should learn POSIX syntax, as well as sed(1), awk(1), and the nuances of other utilities. This isn't hard because the POSIX documentation is infinitely more clear and concise than implementation documentation. A good way to practice is with Solaris, because Solaris' utilities are often annoyingly anachronistic (e.g. grep doesn't even have a recursive mode), but dash isn't a bad place to start, either. And when you do choose to use extended functionality, do so knowingly, having assessed the costs and benefits.
dash/ash
dash/ash
Options+=("$option1")
Files+=("$file1")
$UseVerbose && Options+=("-v")
$UseSecondFile && Files+=("$file2")
command "${Options[@]}" -- "${Files[@]}"
dash/ash
dash/ash
dash/ash
set -- A B C
}
set -- 1 2 3 4
foo
printf "$# -> $*\n"