cercan
cercan

Reputation: 15

Bash Environment Variable

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

Upvotes: 1

Views: 70

Answers (1)

David Lukas
David Lukas

Reputation: 1229

Wouldn't an alias be better for this case?

alias dummy="less foldername/`ls -tr foldername/ | tail -n 1`"

Then you can use:

dummy

Alias vs export

I add -tr options to ls:
-t - sort by time & date
-r - list in reverse order

Upvotes: 1

Related Questions