Your issue is that you're one directory up from the path you are trying to read. The quick fix would be wc -l "csv-output/$lastCSV".
Bear in mind that parsing ls -t though convenient, isn't completely robust, so you should consider something like this to protect you from awkward file names:
last_csv=$(find csv-output/ -mindepth 1 -maxdepth 1 -printf '%T@\t%p\0' |
sort -znr | head -zn1 | cut -zf2-)
wc -l "$last_csv"
- GNU
find lists all files along with their last modification time, separating the output using null bytes to avoid problems with awkward filenames.
- if you remove
-maxdepth 1, this will become a recursive search
- GNU
sort arranges the files from newest to oldest, with -z to accept null byte-delimited input.
- GNU
head -z returns the first record from the sorted list.
- GNU
cut -z at the end discards the timestamp, leaving you with only the filename.
You can also replace find with stat (again, this assumes that you have GNU coreutils):
last_csv=$(stat csv-output/* --printf '%Y\t%n\0' | sort -znr | head -zn1 | cut -zf2-)