I have a shell script that has to find the newest file on a remote host. I have this bit:
ssh -q $HOSTNAME -t ls -t -1 /path/to/somewhere/ | head -n 1
It prints the first line, then waits and doesn't terminate.
However if I remove the | head -n 1
, then it'll print all the files in order and then terminate regularly and return control flow to my terminal. So the SSH command part is terminating fine, but not the head part. What's going on? How do I get the head to work?
-q
or perhaps do2>&1
to catch stderr too..