LinuxAnswers - the LQ Linux tutorial section.
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 08-15-2012, 10:37 PM   #1
Registered: Sep 2009
Location: Perth, W.A.
Distribution: Slackware 14, Debian 7, FreeBSD, OpenBSD
Posts: 179

Rep: Reputation: 35
Bash command line backreference

Using lists on the bash command line, is there a way to reference a parameter appearing earlier in the command list?

For example, I have two common use cases:
mkdir XXX && cd XXX
If I type these two commands separately, after the mkdir I would type cd <alt-.><Enter>.

Or I could do
mydir=XXX mkdir $mydir && cd $mydir
but that is more typing than I want.

The second use case is similar:
chmod +x XXX && mv XXX bin
Same deal.

Ideally, I would like to type something like
chmod +x XXX && mv <alt-2> bin
where readline would dereference alt-2 to the third word in the first command.

Is there such a feature in readline?


Last edited by padeen; 08-15-2012 at 10:39 PM.
Old 08-16-2012, 03:56 PM   #2
Registered: Jan 2011
Posts: 91

Rep: Reputation: 8
Hello Nick,
If I understand what you're asking, I think you can get it with "!:2". Check



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
bash: command works at command line, but not via an alias porphyry5 Programming 3 03-17-2012 02:48 PM
how to use pipe (|) in a one-line bash command gstt Programming 4 10-06-2010 07:54 PM
[SOLVED] bash command line arguments izghitu Linux - Software 4 07-01-2010 09:23 AM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 11:21 AM
One line command - bash da_marius Linux - General 3 11-06-2007 12:24 AM

All times are GMT -5. The time now is 01:29 PM.

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 @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration