I'm trying to write a simple script to take a previous command that was (accidentally) written in a non-English layout, convert everything into correct symbols and run it. I'm using Bash 4.3.11.
My current code looks like this (I'm not a programmer, just trying to learn this for general usability):
echo !! | sed -e "y/first-set-of-symbols/second-set-of-symbols/" | bash
The problem is, when I run the script from a file, I get this: "bash: line 1: !!: command not found", but when I just copy paste the whole command, it does what it's expected to do; if I change the echo part to something like "echo test-command" in the script file, that works when I run the script, too.
Could someone please help me understand why !! isn't working from a script here? Is it supposed to?
I am also open to any suggestions on how to do what I'm trying to do in a better / more efficient / more elegant way.
(I'm not using tr, because, apparently, it doesn't work with Unicode, or so they say—at least it doesn't work for me at all.)
!!
( previous command) might not be defined, thussed
turn!!
into!!
and| bash
(pipe bash) search for a command named!!
!!
is not expanded inline. I'd say tho that you need to pass the broken command as an argument, not try to fetch it from the terminal history. Could you add some more code to get a better insight? That said, trying to auto-correct commands seems like a very bad idea, especially if you run something as root.