Timeline for Why does sudo ignore aliases?
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 13, 2017 at 12:22 | history | edited | CommunityBot | replaced http://askubuntu.com/ with https://askubuntu.com/ | |
| Feb 16, 2015 at 9:25 | comment | added | mikeserv | I know what type does - in bash. You understand though, that the quotes are doubled right? Have you tried it with an alias that contained single quotes? Anyway, you're right about my thing not working - you need either eval "sudo sh -c "$(... or eval "'sudo $(alias alias_name| cut -d\' -f2-)". The thing is aliases are basically prearranged evals - the alias utility is spec'd to output their contents so that it can be safely reinput to the shell. I guess your xargs is implemented then to flatten the whitespace? Just be careful with that, ok? | |
| Feb 16, 2015 at 8:22 | comment | added | loved.by.Jesus | @mikeserv I am sorry you didn't get it ;-) xargs do not strips the quotes. It is grep who takes the resolved command from between the quotes. You know type -a alias_name returns something like alias_name is aliased to command_within_quotes. By the way I have tried your command and didn't work on my ubuntu :-(. Is it the return of type -a different between linux versions? (i doubt it). | |
| Feb 15, 2015 at 20:37 | comment | added | mikeserv | Oh wait a minute - I get it - you're using xargs to strip the quotes, and grep to strip the leading =. Kinda clever, but probably unnecessary. eval "sudo $(alias aliasname | cut -d= -f2-)" is likely better - xargs won't always handle the quotes correctly, and there could be more than one = in there. | |
| Feb 15, 2015 at 20:34 | review | Late answers | |||
| Feb 15, 2015 at 20:39 | |||||
| Feb 15, 2015 at 20:18 | history | edited | loved.by.Jesus | CC BY-SA 3.0 | added 118 characters in body |
| Feb 15, 2015 at 20:16 | review | First posts | |||
| Feb 15, 2015 at 20:51 | |||||
| Feb 15, 2015 at 20:12 | history | answered | loved.by.Jesus | CC BY-SA 3.0 |