Reputation: 1112
ls -lAtr /data/log.* | tail -1 | awk '{ printf $9 }' > $logfile
echo $logfile
cat $logfile # I want to cat the content of this log file, but this wouldn't work
logfile2=/usr/some/path/text.log
echo $logfile2
cat $logfile2 # This work
I am new to shell programming, I wondering how do I convert the logfile into something like logfile2(Did I ask the right question?), so that I can treat it like a file and read from it.
Upvotes: 0
Views: 76
Reputation: 11593
Think you're looking for (works in bash as well)
logfile2="$(</usr/some/path/text.log)"
From ksh
man page
$(cat file) can be replaced by the equivalent but faster $(<file).
e.g.
> cat text.log
line 1
line 2
> ksh
> logfile2="$(<text.log)"
> echo "$logfile2"
line 1
line 2
Upvotes: 1
Reputation: 361595
Are you trying to store the result of ls|tail|awk
in $logFile
? If so:
logFile=$(ls -lAtr /data/log.* | tail -1 | awk '{ printf $9 }')
However, you shouldn't parse the output of ls
.
Upvotes: 1