I am trying to count the number of files in a remote directory.
I have the following code:
ssh server.com<<RUNTHIS
FILE_COUNT=$(ls -AU /foo/bar/test_dir)
echo "$FILE_COUNT" > ~/file_count.txt
RUNTHIS
When I run this I get: ls: /foo/bar/test_dir No such file or directory
But the directory is there. If I do ls /foo/bar/test_dir directly to the server it lists the directory.
Also the following works and saves the contents to the file:
ssh server.com<<RUNTHIS
ls -AU /foo/bar/test_dir > ~/file_count.txt
RUNTHIS
What is wrong in the first snippet?