1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.