Following is my bash Script:
#!/bin/bash
echo "directory: $1"
echo "filename: $2"
echo "username: $3"
echo "destination: $4"
echo "host: $5"
SEARCH=$2*
echo "Search: $SEARCH"
for i in 'ssh $3@$5 find $1 -type f -name SEARCH'
do
echo $PWD
FILE=$i
echo "FILE= $FILE"
scp $3@$5:$FILE $4
done
Here is my output:
directory: **Correct Directory**
filename: **Correct Filename**
username: **Correct username**
destination: ./STORAGE
host: **Correct Host**
Search: filename*
/Users/ranjanasinha/ransinha/POS-INVESTIGATION
FILE= ssh $3@$5 find $1 -type f -name $SEARCH
scp: ssh: No such file or directory
cp: $3@$5: No such file or directory
cp: find: No such file or directory
cp: $1: No such file or directory
cp: -type: No such file or directory
cp: f: No such file or directory
cp: -name: No such file or directory
I'm expecting the FILE to have the found filenames. My question is why does "i" not get the found files? What is wrong with the command?
for i in $(ssh $3@$5 find $1 -type f -name $SEARCH)for i in $(ssh $3@$5 "find '$1' -type f -name '$SEARCH'")-- the double-quotes allow the local shell to substitute$1and$SEARCH, but then the single quotes (just passed through by the local shell) keep the remote shell from doing silly things like prematurely expandingfilename*into a list of matching filenames in the working directory. See here for more explanation.