I want to define a permanent environment variable to view the last text file in a folder. I added this line in .bashrc
file:
export DUMMY="less foldername/`ls foldername/ | tail -n 1`"
The folder is like this:
foldername/
|_ file1
|_ file2
|_ file3
|_ file4
...
The problem is, whenever I use $DUMMY
, it opens always the same file (e.g. file3
) which is one of the last ones but not very recent one and it is not changing. What is my mistake?
Thank you
CodePudding user response:
Wouldn't an alias
be better for this case?
alias dummy="less foldername/`ls -tr foldername/ | tail -n 1`"
Then you can use:
dummy
I add -tr
options to ls
:
-t
- sort by time & date
-r
- list in reverse order