Reputation: 2231
I want to get the latest file in a directory using the ls -lrt
command and store it in a variable and then run the rest of the code based on it.
This is my snippet:
LATEST_FILE=`ls -rt $INPUT_LOCATION/somefile*.utf.gz | tail -1`
**{I want to check if Latest file is valid. If Yes proceed further, if not exit}**
python mycode.py $LATEST_FILE
I tried this:
if [$LATEST_FILE = ""]
then
echo "FIle does not exists"
exit 0
fi
This works fine if the file is not present. But if the file is present, then it throws this error:
./script.sh[5]: [somefile123.utf.gz: not found [No such file or directory]
Please help me with this.
Upvotes: 0
Views: 463
Reputation: 2164
You are missing two spaces and quotation marks:
if [ "$LATEST_FILE" = "" ]
Upvotes: 1