Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 01-28-2010, 09:09 PM   #1
LQ Newbie
Registered: Nov 2006
Posts: 19

Rep: Reputation: 1
Using shortcuts/alias inside a Linux Bash Command

I know that using alias I can run a whole command with a shortcut. But my requirement is to use parts of a long command and in between I have to pass some user defined values.
E.g. Suppose I have to routinely copy a directory to another remote directory on a remote machine.
The remote machine name is quite long as well as the directory path to which I want to copy the files into.
So the command to do scp would look like this
$ scp -r ./<source_directory>

Now I want to do some sort of aliasing (say "ecp") so that I just need to pass the source_directory name and the ecp command and do my job.
Can you give me any suggestion on how can I do this in a convenient way?
Old 01-28-2010, 09:20 PM   #2
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 67
You need to do it with a function, or just create a tiny executable and put it in your $PATH
Old 01-29-2010, 01:26 PM   #3
Senior Member
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
yes you will need a function...

you can through it in your .profile, or if you use bash .bashrc.

ecp () {
scp -r $1

ecp /path/to/dir

you can get fancy too, say you want to copy to dest_dir and and append the date to the directory you are copying over... you can do it like so

ecp () {
scp -r $1${1}.`date +%m-%d-%Y`

all up to you.
1 members found this post helpful.
Old 01-30-2010, 04:52 AM   #4
LQ Newbie
Registered: Nov 2006
Posts: 19

Original Poster
Rep: Reputation: 1

That works very well...
Cool solution man...


alias, command, shortcuts

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Bash Shell Keyboard Shortcuts For Linux Users LXer Syndicated Linux News 0 04-01-2007 03:16 PM
[Bash] Command inside a variable yvovandoorn Programming 5 01-20-2007 06:48 PM
Bash: command works but not inside of for loop. RijilV Programming 3 05-21-2006 08:29 PM
alias not workin inside a script sanjith11 Programming 7 08-31-2005 03:36 PM
Creating mult command alias in BASH labob Linux - Newbie 1 11-18-2004 07:37 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration