【发布时间】:2013-03-16 22:35:46
【问题描述】:
我正在寻找使用 Bash 从命令输出中填充多个数组的最佳方法。
我现阶段想出的解决办法是:
i=1
ls -al | while read line
do
# Separate columns into arrays
array_filetype[ $i ]=`echo $line | awk '{print $1}'`
array_owner[ $i ]=`echo $line | awk '{print $3}'`
array_group[ $i ]=`echo $line | awk '{print $4}'`
echo "${array_filetype[$i]} - ${array_owner[$i]} - ${array_group[$i]}"
(( i++ ))
done
输出是:
drwxrwxr-x - arsene - arsene
drwx--x--- - arsene - arsene
-rw-rw-r-- - arsene - arsene
-rw-rw-r-- - arsene - arsene
-rw-rw-r-- - arsene - arsene
-rw-rw-r-- - arsene - arsene
-rw-rw-r-- - arsene - arsene
-rwx------ - arsene - arsene
-rwx------ - arsene - arsene
-rwxr-xr-x - arsene - arsene
-rwx------ - root - root
提前致谢。
砷
【问题讨论】:
标签: arrays bash file command output