Timeline for How to run a previous command (that uses an alias) with sudo, both in command line and with an alias
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 25, 2020 at 16:05 | comment | added | Ness |
@BANJOSA So why does that work when alias please='sudo $(history -p !!)' does not work? I still can't figure out how to get it to do that.
|
|
| Feb 24, 2020 at 9:08 | comment | added | BANJOSA |
I've tried adding a new alias alias please='sudo nano /etc/hosts' where nano is an alias of vimand when I executed please is was working and asking the password for sudo.
|
|
| Feb 21, 2020 at 23:09 | answer | added | user232326 | timeline score: 1 | |
| Feb 21, 2020 at 19:27 | history | edited | Ness | CC BY-SA 4.0 |
added 148 characters in body
|
| Feb 21, 2020 at 18:34 | comment | added | Ness | @BANJOSA So that does indeed work. Now how would I use an alias to do that command? I'd rather type "pls" instead of "sudo !!". But again, this is mostly to see if it can be done. | |
| Feb 21, 2020 at 18:32 | comment | added | Ness | @guillermochamorro Yes, that is out of the question. | |
| Feb 21, 2020 at 17:13 | comment | added | BANJOSA |
yes it but i've aliased it to vim. I've done the same experiment with alias nano='vim'and alias sudo='sudo 'and the executed nano /etc/hosts and afterwards executed sudo !! and it opened my hosts file with vim
|
|
| Feb 21, 2020 at 16:52 | comment | added | schrodingerscatcuriosity |
@BANJOSA Mmh, vi is a system command... are you sure that you are not just running vi?
|
|
| Feb 21, 2020 at 16:47 | comment | added | BANJOSA |
alias sudo='sudo ' worked for my aliased command. i have na alias vi='vim' if i run vi /etc/hosts and then run sudo !! it runs the previous aliased command with sudo.
|
|
| Feb 21, 2020 at 16:30 | comment | added | schrodingerscatcuriosity |
Creating a script with the command, and add it to secure_path is out of the question?
|
|
| Feb 21, 2020 at 15:58 | comment | added | Ness |
This is mostly to see how it can be done, as I've spent hours trying to figure this out. As of right now, I am settling for a keyboard shortcut in my .inputrc file with this line: "\es":"\C-p\C-asudo " This sets Alt-s to go to the previous line, go to the beginning of that line, and type "sudo ".
|
|
| Feb 21, 2020 at 15:55 | history | asked | Ness | CC BY-SA 4.0 |