diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-03-21 15:58:08 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-03-21 15:58:08 (EDT) |
commit | 0e7634fee188d25165661044c3eb719e333d6ca3 (patch) | |
tree | cd6265072743942e1fd0610c0be383f41c013e53 /tools | |
parent | 33d188e8dddded7d3d57c202fac562041ca35357 (diff) |
tools/mtime.sh: Parse ls output with read, not cut
cut treats multiple delimiter characters as empty fields, increasing the
field count an indeterminate amount for fields with whitespace delimiter
padding. BusyBox's ls outputs:
-rw-r--r-- 1 1000 1000 1935 Mar 16 16:31 man/opkbuild.1in
cut counts the owner field, not the month, as field 6. And fields 7 and
8 are empty.
The shell interpreter's field splitting is better suited for this job,
so just use read.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/mtime.sh | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/mtime.sh b/tools/mtime.sh index c2f9dfa..7207f9e 100755 --- a/tools/mtime.sh +++ b/tools/mtime.sh @@ -23,14 +23,19 @@ get_mtime() { local file="${1}" shift 1 + local mode= + local links= + local owner= + local group= + local size= local m= local d= local y= local now_m= local now_y= - read m d y <<-EOF - $(LC_ALL=POSIX ls -l "${file}" | cut -d ' ' -f 6-8) + read -r mode links owner group size m d y <<-EOF + $(LC_ALL=POSIX ls -l "${file}") EOF case "${m}" in 'Jan') m=1;; 'Feb') m=2;; 'Mar') m=3;; 'Apr') m=4;; |