Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alias a multipart command on the lefthand side in bash

I have a command (in Linux Bash) that I want to prevent myself from ever running with a specific option. However, I want to still run that command with other options. So for example the following are OK:

command opt1
command opt2

But I want to disable

command badopt

I was thinking of doing this by aliasing it to a nonexistant command in my profile, like

alias "command badopt"=djskagldjkgldasg

but this doesn't seem to work. Any other suggestions for (easily) disabling my ability to use this specific option while preserving my ability to use other options?

like image 687
Stephen Avatar asked Dec 31 '25 12:12

Stephen


1 Answers

$ cat >> $HOME/.bashrc
shutdown () {
  if [ "x$1" = x-h ]; then
    echo Please do not run shutdown with the -h option.
    return
  fi
  /sbin/shutdown "$@"
}

# updated

like image 70
DigitalRoss Avatar answered Jan 03 '26 02:01

DigitalRoss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!