8

i add an alias in .bashrc

alias sr='sudo /etc/rc.d/[parameter?] restart'

sr network -> sudo /etc/rc.d/network restart

sr sshd -> sudo /etc/rc.d/sshd restart

could it be achieved, thanks!

codeforester
  • 39,467
  • 16
  • 112
  • 140
toughtalker
  • 461
  • 2
  • 6
  • 14

4 Answers4

13

Use a shell function instead. eg:

function sr () {
  sudo /etc/rc.d/"$1" restart
}
Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
6

I'm surprised nobody mentioned to use a function

function sr() { 
  sudo /etc/rc.d/"$@" restart 
}
SiegeX
  • 135,741
  • 24
  • 144
  • 154
0

Use a function rather than an alias:

function sr() { sudo /etc/rc.d/$@ restart; }
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
0

Aliases in bash do not accept parameters. However, you could define a function instead:

function sr() { sudo /etc/rc.d/$1 restart; }
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190