I want to check if only one instance of a file exists before going on to process that file.
I can check how many instances exist using this command:
ls -l $INPUT_DIR/${INPUT_FILE_PREFIX}cons*.csv.gz | wc -l;
ls: command not found
if [ls -l $INPUT_DIR/${INPUT_FILE_PREFIX}cons*.csv.gz | wc -l = '1']
then
echo "Only 1 File Exists";
fi
You were almost there:
if [ $(ls -l $INPUT_DIR/${INPUT_FILE_PREFIX}cons*.csv.gz 2>/dev/null | wc -l) == 1 ]
then
echo "Only 1 File Exists";
fi
evaluates the result and compares with double equals. Also, put spaces before and after square brackets.
Also, filter out the case where no file matches (avoids no such file or directory
error)