[NTLUG:Discuss] Bash command line completion

dcweaver dcweaver at gmail.com
Fri Jun 10 07:39:47 GMT+5 2016


Hi Rusty,

You might try this:
Substitute a specific argument for a specific command.

In the example below, *!cp:2* searches for the previous command in history
that starts with cp and takes the second argument of cp and substitutes it
for the ls -l command as shown below.

# *cp ~/longname.txt /really/a/very/long/path/long-filename.txt*
# *ls -l !cp:2*
ls -l /really/a/very/long/path/long-filename.txt

In the example below, *!cp:$* searches for the previous command in history
that starts with cp and takes the last argument (in this case, which is
also the second argument as shown above) of cp and substitutes it for the
ls -l command as shown below.

# *ls -l !cp:$*
ls -l /really/a/very/long/path/long-filename.txt

Hope this helps,
Dennis

On Fri, Jun 10, 2016 at 12:25 AM, Rusty Haddock <kd4wlz at gmail.com> wrote:

> Shell variable or an alias I think are your best bets.  All methods are
> going to involve some setup but these have the least amount.
> On Jun 9, 2016 11:31 PM, "Leroy Tennison" <leroy.tennison at verizon.net>
> wrote:
>
> > I'm looking for a way to recover only the first few words of the
> > immediately previous command.  For example,given the below
> >
> >     ip route delete 192.168.100.0/24 dev eth0
> >
> > I want to easily repeat
> >
> >     ip route delete
> >
> > so I can copy/paste additional routes from the output of 'ip route'
> > (working with a firewall which has 10 interfaces, doing testing).
> >
> > I realize I could write an alias but was hoping for something more
> direct,
> > either I'm not searching for the right thing or the web isn't being
> > helpful, ideas?
> >
> > _______________________________________________
> > http://www.ntlug.org/mailman/listinfo/discuss
> >
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>


More information about the Discuss mailing list