I have a text file on the server created scp_command.txt which I need to use as the content changes dynamically.
So retrieving the content this way.
copy_command="$(cat $CI_PROJECT_DIR/scp_command.txt)"
And the content looks this way.
echo $copy_command
scp -q -i ssh_key.pem %s ec2-user@ec2-35-86-96-6.us-west-2.compute.amazonaws.com:~
To use this command, I tried like this.
$(echo ${copy_command/"%s"/"~/.project-n/1.txt"})
But I am getting error as below.
~/.project-n/1.txt: No such file or directory
new_copy_command=${copy_command/"%s"/"~/.project-n/1.txt"}
echo $new_copy_command
scp -q -i ssh_key.pem ~/.project-n/1.txt ec2-user@ec2-35-86-96-6.us-west-2.compute.amazonaws.com:~
$new_copy_command
~/.project-n/1.txt: No such file or directory
$($new_copy_command)
~/.project-n/1.txt: No such file or directory
But if I ran the content directly, it works,
echo $new_copy_command
scp -q -i ssh_key.pem ~/.project-n/1.txt ec2-user@ec2-35-86-96-6.us-west-2.compute.amazonaws.com:~
scp -q -i ssh_key.pem ~/.project-n/1.txt ec2-user@ec2-35-86-96-6.us-west-2.compute.amazonaws.com:~