Skip to main content
deleted 2 characters in body
Source Link
SebMa
  • 2.5k
  • 6
  • 34
  • 48

I've written my own Sudo bash function to do that, it works to call functions and aliases :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && $(whichcommand sudo) bash -c "$(declare -f $firstArg);$firstArg $*" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo ' eval "sudo $@" else $(whichcommand sudo) "$@" fi } 

I've written my own Sudo bash function to do that, it works to call functions and aliases :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && $(which sudo) bash -c "$(declare -f $firstArg);$firstArg $*" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo ' eval "sudo $@" else $(which sudo) "$@" fi } 

I've written my own Sudo bash function to do that, it works to call functions and aliases :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && command sudo bash -c "$(declare -f $firstArg);$firstArg $*" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo ' eval "sudo $@" else command sudo "$@" fi } 
Fixed a bug
Source Link
SebMa
  • 2.5k
  • 6
  • 34
  • 48

I've written my own Sudo bash function to do that, it works to call functions and aliases :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && $(which sudo) bash -c "$(declare -f $firstArg);$firstArg $@"$*" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo ' eval "sudo $@" else $(which sudo) "$@" fi } 

I've written my own Sudo bash function to do that, it works to call functions and aliases :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && $(which sudo) bash -c "$(declare -f $firstArg);$firstArg $@" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo ' eval "sudo $@" else $(which sudo) "$@" fi } 

I've written my own Sudo bash function to do that, it works to call functions and aliases :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && $(which sudo) bash -c "$(declare -f $firstArg);$firstArg $*" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo ' eval "sudo $@" else $(which sudo) "$@" fi } 
Fixed the bug for which sudo could not call aliases
Source Link
SebMa
  • 2.5k
  • 6
  • 34
  • 48

I've written my own Sudo bash function to do that, it works to call functions in sudo mode but it does not work withand aliases yet :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && $(which sudo) bash -c "$(declare -f $firstArg);$firstArg $@" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo '   shift && sudoeval $firstArg"sudo "$@"$@" else $(which sudo) "$@" fi } 

If anyone knows why my function does not work with aliases, please feel free to edit my answer.

I've written my own Sudo bash function to do that, it works to call functions in sudo mode but it does not work with aliases yet :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && $(which sudo) bash -c "$(declare -f $firstArg);$firstArg $@" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo '   shift && sudo $firstArg "$@" else $(which sudo) "$@" fi } 

If anyone knows why my function does not work with aliases, please feel free to edit my answer.

I've written my own Sudo bash function to do that, it works to call functions and aliases :

function Sudo { local firstArg=$1 if [ $(type -t $firstArg) = function ] then shift && $(which sudo) bash -c "$(declare -f $firstArg);$firstArg $@" elif [ $(type -t $firstArg) = alias ] then alias sudo='\sudo ' eval "sudo $@" else $(which sudo) "$@" fi } 
Replaced "type" by "declare -f" in the "bash -c" commands
Source Link
SebMa
  • 2.5k
  • 6
  • 34
  • 48
Loading
Source Link
SebMa
  • 2.5k
  • 6
  • 34
  • 48
Loading