0

Look at this: I want to let ls- l always show the date formatted as long-iso. I was told to add a file /etc/profile.local with the line export TIME_STYLE=long-iso. I did so, as shown below under #1.

However, there is no environment variable TIME_STYLE as shown in #2.

#3 shows the version of the ls command (this all happens with Xubuntu 16.04 LTS).

As shown in the output of #4, ls does not format the date part as long-iso.

Ok, if it is just because the environment variable TIME_STYLE is missing (why?), then I set it in #5 and, as a proof that it exists, I echo it in #6.

Despite of that, ls -l in #7 does not honour that!

Of course, if I explicitly require the date format as long iso as shown in #8, the date is formatted that way. But I want to let ls -l always show the date as long-iso without having to tell it on every invocation and I also want to avoid to create an alias for ls -l which incorporates this parameter (which of course would be easy to do, but that's not sportsmanlike).

What's wrong here? Some basic misunderstanding? Or is it really a bug? I can't really believe it in ls -l!

a@v:~$ cat /etc/profile.local                 # 1
export TIME_STYLE=long-iso
a@v:~$ echo "${TIME_STYLE}"                   # 2

a@v:~$ ls --version                           # 3
ls (GNU coreutils) 8.25
...
a@v:~$ ls -l /etc/profile.local               # 4
-rw-r--r-- 1 root root 27 Dez 30 19:18 /etc/profile.local
a@v:~$ TIME_STYLE=long-iso                    # 5
a@v:~$ echo "${TIME_STYLE}"                   # 6
long-iso
a@v:~$ ls -l /etc/profile.local               # 7
-rw-r--r-- 1 root root 27 Dez 30 19:18 /etc/profile.local
a@v:~$ ls -l --time-style="${TIME_STYLE}" /etc/profile.local  # 8
-rw-r--r-- 1 root root 27 2018-12-30 19:18 /etc/profile.local
a@v:~$

Edit: As dessert taught us: After using sudo nano to append a line export TIME_STYLE=long-iso to the existing file /etc/bash.bashrc I got:

a@v:~$ ls -l /etc/bash.bashrc -rw-r--r-- 1 root root 2374 2019-01-02 00:23 /etc/bash.bashrc a@v:~$

Thank you, dessert, for your help and especially for your explanations why ls -l did not work as intended.

  • You forgot to export the variable, TIME_STYLE=long-iso ls -l as well as export TIME_STYLE=long-iso; ls -l both work as expected. – dessert Dec 31 '18 at 10:45
  • /etc/profile.local is not recognized by bash, see man bash/INVOCATION. Add the export line to either /etc/bash.bashrc or preferably your ~/.bashrc and it will be read by every new bash interactive shell. – dessert Dec 31 '18 at 10:59
  • 1
    You need to export the variable because ls is an external program rather than a shell builtin. – dessert Dec 31 '18 at 11:05

0 Answers0