I'm looking for the best way to fill in multiple arrays from command's output using Bash.
The solution I figured out at this stage is:
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
The output is:
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
Thanks in advance.
Arsene