3

I often do this:

scp some_file [email protected] 

I'm annoyed by this because I always copy-paste this line, and then I need to edit the middle to change the file I want to upload.

Is it possible to tinker with this line so the file name will be at the end and it'll still work?

Basically I want any string of characters that I can paste into a shell, then type a file name and have it upload the file with scp to the server.

5 Answers 5

3

Why not make a super-simple script? Just edit a file named say myscp containing

#!/bin/bash scp $1 [email protected] 

and then chmod +x myscp, so that later you can simply

./myscp some_file 

This is all assuming your myscp script is located at the current directory, otherwise add the path

/path/to/myscp some_file 

or better yet, add the path of the location and this and -hopefully- future scripts to your $path.

1

One of possible solutions:

(read FILE_NAME; scp "$FILE_NAME" [email protected]) <<< some_file 
1

Add to the end of your .bashrc or equivalent for your shell:

my_function_name() { if [ -r "$1" ]; then scp "$1" [email protected] else echo "File does not exists or can not be read, $1" >&2 return 1 fi } 

Change my_function_name to your needs.

Now you can just invoke the function by name and pass a file as argument and it will be tested for read access and run scp with it or quit if can not read it.

Note that I used return instead of exit because it will be loaded by your interactive shell, and if you use exit the shell will terminate.

1

Use ssh_config to shorten your [email protected]. Create a file ~/.ssh/config with

Host alias HostName long.server.name.com User really 

and then connect simply using scp some_file alias.

0

No, you can't change the order of the parameters without wrapping it in a shell script, but you could...

R='[email protected]' scp some_file $R scp other_file $R ... 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.