本教程的作者做得很好,但没有解释他的用法printf
。它对我来说不起作用。它位于http://www.linuxjournal.com/content/bash-arrays
我用
#!/bin/sh
ARRAY=(one two three four [5]=five)
echo "Array size: ${#array[*]}"
echo "Array items:"
for item in ${array[*]}
do
printf " %s\n" $item
done
echo "Array index:"
for index in ${!array[*]}
do
printf " %d\n" $index
done
echo "Array items and indexes:"
for index in ${!array[*]}
do
printf "%4d: %s\n" $index ${array[$index]}
done
我明白了
cchilders@C02S21TWG8WMMBP:~/fake
$ ./array_example1.sh
Array size: 0
Array items:
Array index:
Array items and indexes:
我如何在 bash 脚本中运行 printf 等?谢谢