Shell Change in /bin/ls

jrm@

Developer
More of my scripts had hiccups after upgrading to 11.0-RC2. In this case the change was in /bin/ls, and specifically the -f option.

From ls(1) on 10.3-RELEASE:
-f Output is not sorted.
From ls(1) on 11.0-RC2:
-f Output is not sorted. This option turns on -a. It also negates the effect of the -r, -S and -t options. As allowed by IEEE Std 1003.1-2001 (“POSIX.1”), this option has no effect on the -d, -l, -R and -s options.
So, heads up if you also use
Code:
ls -f | while read var; do....
The commit message that (re-)introduced this change is interesting.
Make -f set -a, as required by the standard.

From the original OpenBSD commit message:

restore the traditional behavior of -f implying -a; apparently Keith
Bostic forgot to restore it when the -f flag was put back on 2nd of
September 1989, after being removed on 16th of August as a
consequence of issues getting it working over NFS, so deviation from
traditional UNIX behavior in all BSDs looks like an historical
accident; as a side effect, this change accommodates behavior of
this option to IEEE Std 1003.1-2008 (``POSIX.1'').
https://svnweb.freebsd.org/base?view=revision&revision=264064
 
You should be using the shell's globing to handle this:

Code:
for file in *; do
  ....
done

I'm sure there's a bit more to your script and maybe there's something you're depending on with ls' output. However, the general rule is "Don't parse ls output."
 
Back
Top