Is there a way to redirect output on Linux to a former argument. For example,
sort file.txt > file.txt
Would there be a way to avoid typing file.txt again?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
For some commands, there may be some sort of option to avoid this kind of redundancy. But it is not the case generically for all commands in Linux.
In your case, the correct way to write what you already have is
sort file.txt -o file.txt
This will sort
file.txt and write the results back to the same file.
If you want to save the argument so you don't have to keep typing a long file name, you could store it in a bash variable:
i="file.txt"; sort $i -o $i