Everybody says it is bad, bad, very bad to use ls to parse. This is a script that will pick out a log file. I don't want to glob the whole directory, $1 is the name of the file I want to look at, and of those files, I only want to see the last two. How do I do this without using ls ?
for i in $(ls -ltr ~/logs/autosys/*${1}* | tail -2) ; do
if [[ ${i} =~ ".out" ]] ; then
tailpath=$(echo ${i%.*} | awk '{print $9}')
fi
done
~/logs/autosyswith names containing$1, then do something with them".ls -t | head -n2will give you just the filename, you don't need to parse thelsoutput.