linux - Issues using the tilde ~ in a simple function wrapper around scp -
i want place simple bash
function in .bashrc
wraps around scp
command accepting 'source' argument , 'destination' argument, , far have tried both
function send() { eval "scp $1 user@annoyingly-long-server-name:$2" }
and
function send() { scp $1 user@annoyingly-long-server-name:$2 }
...but when call either of above la
send file.txt ~/
i error scp: home-directory-on-remote-machine: operation not supported
. after echoing each argument, seems tilde expanded remote machine's home directory before evaluation. how can prevent this?
first, of can use ssh-keys prevent typing of passwords.
before use function once:
ssh-copy-id remotehostname
it considered better use keys instead of passwords ssh , true scp.
second, don't need eval
.
function send() { scp "$1" user@annoyingly-long-server-name:"$2" }
and finally, need use explicit path names:
send foo /home/luke/foo
because ~
how not evaluated /home/luke/
.
update, side story:
if motivation writing function send
annoyingly-long-server-name
should know /home/luke/.ssh/config
. inside file can wonders:
host a-nicer-alias hostname stupid-host-name.verylongdoamin.com user luke
then can ssh a-nicer-alias
Comments
Post a Comment