I set up an alias this morning to help finding the latest log file in a directory. My alias looks like
alias latest="ls -lat | grep ^- | awk '{print \$8}' | head -1"
In my research so far this morning I've read a blog - ParsingLS which tells me this is probably not the best way to do it - let's ignore that for now, I can look at making a better alias using find
later. For now assume I have a perfectly working command expected to output a filename from the current directory.
I thought I was going to be able to do latest | vi
, to open the latest modified file in the directory, but it seems this won't work - vi complains that the output is not a terminal. I saw a stackoverflow question which suggested the issue is related to subshells and piping and so tried
latest | vi < `tty` > `tty`
But that just gets me
`tty`:ambiguous redirect
I'm sure there's something basic I am not getting about pipes here - I only recently started trying to use them in earnest, any ideas?