In Linux terminal, normally I can copy files from another unix server using:
scp -r [email protected]:/data/filename ./
which secure copies the remote file to my current directory. I've made sure this command line works well before I did anything below.
To save time of typing the long front part, I create an alias for scp -r [email protected]:
, and receive arguments for /data/filename
and ./
from command line.
Opening the ~/.bashrc file, first I tried
alias scpfile="scp -r [email protected]:'$1' '$2'"
In command line, I typed scpfile /data/filename ./
,
but I got an error message as follows:
error: unexpected filename: .
Then I tried another one
function scpfile() {
scp -r [email protected]:$1 $(pwd)
}
or
function scpfile() {
scp -r [email protected]:"$1" "$(pwd)"
}
In command line, I typed scpfile /data/filename
,
but it's also wrong with error message:
/data/filename: No such file or directory
Can someone help if you know the answer to it?
Moreover, I've tried the answers shown in Make a Bash alias that takes a parameter, but still not working!
scp -r [email protected]:"$1" "$(pwd)"
should be fine). If that also fails for you, post more details, including full error message.$1
and$(pwd)
--or better,$PWD
--should both be quoted).~/.ssh/config
and then the command is justscp edu:/some/file .
home2edu
and drop the alias.