Issue
I have a VM where I have a folder A which contains doc1.txt
doc2.txt
king1.so
and king2.so
I am trying to list the files of a specific extension using ssh
from another VM.
VAR_PATH="/predefined/path/to/A"
echo $VAR_PATH
for file_path in `ssh [email protected] "find $VAR_PATH -iname "*.so""`
do
echo $file_path
done
This is not working and giving me error as
find: paths must precede expression: sample.so
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path…] [expression]
the same command works when I am hardcoding the path in find
command
for file_path in `ssh [email protected] "find /predefined/path/to/A -iname "*.so""`
do
echo $file_path
done
How do I pass path variable inside the ssh command inside this for loop
Solution
try this one: (centos 8 test passed)
D=/tmp/test/ && for i in `ssh xxx@xxxxx "find $D -name '*.so'"`;do echo $i;done
Answered By – baozilaji
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0