Question

Below is my shell script in which I am trying to append $element in my below scp call in the if statement block.

for element in ${x[$key]}; do   # no quotes here
    printf "%s\t%s\n" "$key" "$element"
    if [ $key -eq 0 ]
    then
        scp david@machineB:/data/be_t1_snapshot/20131215/t1_$element_5.data /data01/primary/.
    fi    
done

But whenever I am running my above shell script, I always get like this -

scp david@machineB:/data/be_t1_snapshot/20131215/t1_.data No such file or directory

When I have taken a close look in the above error message, the above scp statement is not right as it should be -

scp david@machineB:/data/be_t1_snapshot/20131215/t1_0_5.data /data01/primary/.

The value of $element should get replaced with 0 but somehow my above appending logic is not working. Is there anything wrong I am doing in the way I am appending $element in my above scp command

Était-ce utile?

La solution

try t1_${element}_5.data

scp david@machineB:/data/be_t1_snapshot/20131215/t1_${element}_5.data /data01/primary/.

when you use t1_$element_5.data, bash will replace $element_5 with its value, you don't have $element_5 defined, so you are getting

t1_.data No such file or directory

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top