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?
ssh server.com "ls -AU" > ~/file_count.txt
(If I recall how to ssh correctly) – SIGSTACKFAULT Oct 19 '17 at 15:07ssh server.com "ls -AU > ~/file_count.txt"
– SIGSTACKFAULT Oct 19 '17 at 16:11ls
). :) – Rastapopoulos Oct 19 '17 at 16:21