Alias as sudo doesn't work
by vinaytp from LinuxQuestions.org on (#50HYP)
Hello All,
Hope everyone is doing good !
I am posting on this forum after really long. I have turned more of network Engineer & use less Linux these days.
I am trying to create an alias for "systemctl status network" to replace "failed" in the output to something else.
Below are the aliases created :-
Code:alias sudo='sudo '
alias systemctl='f(){ if [ $# -eq 2 ] && [[ $1 == "status" ]] && [[ $2 == "network" ]]; then systemctl $1 $2 | sed -e "s/.*failed.*/test/g" ; else systemctl $@; fi };f'If I use the command without sudo it perfectly works as shown below
Code: systemctl status network
a- network.service - LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
test
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/network.serviceBut If I use with sudo it errors out, Can someone please point my mistake ?
Code:$ sudo systemctl status network
-bash: syntax error near unexpected token `('Thanks,
Vinaya


Hope everyone is doing good !
I am posting on this forum after really long. I have turned more of network Engineer & use less Linux these days.
I am trying to create an alias for "systemctl status network" to replace "failed" in the output to something else.
Below are the aliases created :-
Code:alias sudo='sudo '
alias systemctl='f(){ if [ $# -eq 2 ] && [[ $1 == "status" ]] && [[ $2 == "network" ]]; then systemctl $1 $2 | sed -e "s/.*failed.*/test/g" ; else systemctl $@; fi };f'If I use the command without sudo it perfectly works as shown below
Code: systemctl status network
a- network.service - LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
test
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/network.serviceBut If I use with sudo it errors out, Can someone please point my mistake ?
Code:$ sudo systemctl status network
-bash: syntax error near unexpected token `('Thanks,
Vinaya