History Expansion in script

New to Debian (Or Linux in general)? Ask your questions here!

History Expansion in script

Postby Agvaniot » 2017-08-02 16:25

hi. im trying to create a script that just do that :
Code: Select all
^string1^string2

the problem is when im trying to do :
Code: Select all
^$1^$2

the script try to look for a command with that parameters but i want the script to act like i typed it directly to the shell
thanks in advance!
Agvaniot
 
Posts: 37
Joined: 2017-07-26 13:07

Re: History Expansion in script

Postby debiman » 2017-08-03 08:42

what is the '^' supposed to be? Ctrl key? Tab? i don't really understand which shell behavior you want to reproduce.
isn't there a history command?
what exactly are you trying to achieve?
User avatar
debiman
 
Posts: 1086
Joined: 2013-03-12 07:18

Re: History Expansion in script

Postby Agvaniot » 2017-08-03 20:27

debiman wrote:what is the '^' supposed to be? Ctrl key? Tab? i don't really understand which shell behavior you want to reproduce.
isn't there a history command?
what exactly are you trying to achieve?

Code: Select all
^string1^string

is a history expansion which substitute string1 with string2 of the last command
now im trying to create a script to do just that but instead of typing ^string1^string2
i want
Code: Select all
swi string1 string2
as its more convinient for me
Agvaniot
 
Posts: 37
Joined: 2017-07-26 13:07

Re: History Expansion in script

Postby debiman » 2017-08-08 05:06

no answer on stackoverflow either... i'm guessing it isn't possible.
sure, you could try messing around with xdotool or some such, but really it would be bets to
either
- just use the history expansion as is without scripting it
or
- recreate the behavior with other utilities like sed...

you can also try to ask this on #bash on irc.freenode.net
User avatar
debiman
 
Posts: 1086
Joined: 2013-03-12 07:18


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable