linux - How to tell shell command tail not to wait for parameter -
my current code
tail -n 1 `ls -1t /path/*.txt 2>/dev/null | head -n 1` | awk '{print $1}' works fine if there @ least 1 *.txt file in directory.
but if there no such file, tail waiting input , not end.
how need modify code ensure ends if no file present?
did quick test, adding /dev/null "fake" file seems trick.
tail -n 1 `ls -1t /path/*.txt 2>/dev/null | head -n 1` /dev/null | awk '{print $1}'
Comments
Post a Comment