擅长:python、mysql、java
<p>有参数替换,虽然它也可能是非PC的…像间接寻址。</p>
<pre><code>#!/bin/bash
# Array pretending to be a Pythonic dictionary
ARRAY=( "cow:moo"
"dinosaur:roar"
"bird:chirp"
"bash:rock" )
for animal in "${ARRAY[@]}" ; do
KEY="${animal%%:*}"
VALUE="${animal##*:}"
printf "%s likes to %s.\n" "$KEY" "$VALUE"
done
printf "%s is an extinct animal which likes to %s\n" "${ARRAY[1]%%:*}" "${ARRAY[1]##*:}"
</code></pre>
<p>当然,BASH 4方法更好,但是如果你需要一个黑客…只有一个黑客可以。
您可以使用类似的技术搜索数组/散列。</p>