0

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?

2
  • 2
    for i in $(ssh $3@$5 find $1 -type f -name $SEARCH) Commented Feb 21, 2021 at 3:40
  • 1
    You should quote the command properly: for i in $(ssh $3@$5 "find '$1' -type f -name '$SEARCH'") -- the double-quotes allow the local shell to substitute $1 and $SEARCH, but then the single quotes (just passed through by the local shell) keep the remote shell from doing silly things like prematurely expanding filename* into a list of matching filenames in the working directory. See here for more explanation. Commented Feb 21, 2021 at 6:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.