Bash – Alias or Intercept complex bash command with args

bash

How do you create a bash alias for a command with flags? For example, if I run ls -l, I want that to alias to ls -a.

This doesn't work: alias "ls -l"="ls -a"

Another example: If I type reboot now, I want that to simply run reboot.

Would bash functions be useful here?


EDIT: Sorry for the silly ls -l example. This is what I really want: if you executed reboot now, I want it to actually execute reboot. This is why.

Best Answer

Another example: If I type reboot now, I want that to simply run reboot.

Create a function:

reboot() {
  command reboot
}

Now invoking the command reboot would invoke the function reboot which would ignore all parameters passed to it.

That is:

reboot

and

reboot now

would execute the command reboot (without any argument).

Related Question