Recently Written · git

tmpl

Insanely simple templates

git clone https://github.com/equwal/tmpl

Log | Files | Refs


sh/for-array (324 bytes)

1 #
2 # Yes, it really is this hard to do
3 # and it is broken on GNU non-POSIX non-+ support.
4 save () {
5     for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
6     echo " "
7 }
8 
9 old=$(save "$@")
10 myarray=$(save "$@")
11 set -- foo bar baz boo
12 eval "set -- $myarray"
13 for i ; do <++> ; done
14 eval "set -- $old"