Ubuntu – stat –format %N quotes

quotingstatUbuntu

I used stat on two different versions of Ubuntu and it printed different types of quotes.

14.04 (coreutils 8.21-1ubuntu5.1):

$ stat --format %N test.txt
‘test.txt’

16.04 (coreutils 8.25-2ubuntu2):

$ stat --format %N test.txt
'test.txt'

Why does stat use this uncommon quoting style in the older version and is there a way to tell stat which type of quotes it should use?

Edit

I know that in version 8.26 quoting style was introduced for stat (https://savannah.gnu.org/forum/forum.php?forum_id=8745):

  stat --format=%N for quoting file names now honors the
  same QUOTING_STYLE environment variable values as ls.

But prior to this change there should be a consistent behavior between the versions or were there other changes I'm not aware of?

Best Answer

From the GNU stat documentation:

The ‘%N’ format can be set with the environment variable QUOTING_STYLE. If that environment variable is not set, the default value is ‘shell-escape’. Valid quoting styles are:

literal
Output strings as-is; this is the same as the -N or --literal option.

...

shell-escape
Like ‘shell’, but also quoting non-printable characters using the POSIX proposed ‘$''’ syntax suitable for most shells.

...

locale
Quote strings as for C character string literals, except use surrounding quotation marks appropriate for the locale, and quote 'like this' instead of "like this" in the default C locale. This looks nicer on many displays.

stat didn't use this variable in 8.21 (the change was made last November). The output from 14.04 looks like it used QUOTING_STYLE=locale. Presumably that was the (implicit) default then.

Related Question