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!
You can replace $@ with $1 if you only want the first argument. This creates a temporary function f , which is passed the arguments. Alias arguments are only passed at the end. Note that f is called at the very end of the alias.
Bash users need to understand that alias cannot take arguments and parameters. But we can use functions to take arguments and parameters while using alias commands.
Explanation: To declare an alias, the keyword ALIAS is used. Then, the colon sign followed by the name of ALIAS. Then, the name of the object is then specified whose alias is to be created. So, that the duplicate for that object can be created.
The Korn shell, or POSIX shell, allows you to create aliases to customize commands. The alias command defines a word of the form Name=String as an alias. When you use an alias as the first word of a command line, ksh checks to see if it is already processing an alias with the same name.
Use a shell function instead. eg:
function sr () {
sudo /etc/rc.d/"$1" restart
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With