LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash command line backreference (http://www.linuxquestions.org/questions/linux-general-1/bash-command-line-backreference-4175422311/)

padeen 08-15-2012 10:37 PM

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

elucches 08-16-2012 03:56 PM

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


All times are GMT -5. The time now is 05:25 PM.