Many times I have run a command with all the letters in uppercase (maybe because CapsLock was on), and I pressed Enter before realising this.
How can I run the last command with all the letters transformed to lowercase?
Many times I have run a command with all the letters in uppercase (maybe because CapsLock was on), and I pressed Enter before realising this.
How can I run the last command with all the letters transformed to lowercase?
You can accomplish that by adding the following small function (I call it
??
to be very simple, but you can change this as you wish) in your.bashrc
file:Next, when you will run:
the last command will be run with all the letters to lowercase.
Explanation
!!
: this is part of bash's history tools, specifically, it expands to the last command run. So, for example,echo !!
will print out the last command run in this particular shell session."${@,,}
: The construct${foo,,}
will convert the contents of the variable$foo
converted to all lowercase letters.$@
is the array of positional parameters. When used inside a function, it is expanded to the parameters passed to that function.So,
"${@,,}"
will simply convert whatever was passed to the function into lowercase and then execute it. Therefore, running the??
function with!!
as a parameter will convert the last command to lowercase and run it.The key is in the
`
(backticks) quotations - which runs the output as a command.here comes a programmers answer.... use python:
Or Ruby:
Or Perl (probably my favorite):
Or PHP:
Or Awk:
Or Sed:
Or Bash:
Or zsh
Or NodeJS if you have it:
You could also use
dd
(but I wouldn't!):You could also create a small script to do the job:
Which you use like so:
And the one with
sed
,Example:
Output: