LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-15-2012, 10:37 PM   #1
padeen
Member
 
Registered: Sep 2009
Location: Perth, W.A.
Distribution: Slackware, Debian, Gentoo, FreeBSD, OpenBSD
Posts: 208

Rep: Reputation: 41
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:
Code:
mkdir XXX && cd XXX
If I type these two commands separately, after the mkdir I would type cd <alt-.><Enter>.

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

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

Ideally, I would like to type something like
Code:
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?

Thanks,
Nick

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

Rep: Reputation: 11
Hello Nick,
If I understand what you're asking, I think you can get it with "!:2". Check http://www.gnu.org/software/bash/man...rd-Designators
Regards,
Esteban
 
1 members found this post helpful.
  


Reply

Tags
bash



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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:03 PM.

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