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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -