5

I have a bash script that needs to behave differently if a particular alias is defined. Is there a way to test if a particular command is an alias in bash?

  • 8
    type -t <command> – jimmij Jun 8 '16 at 18:55
  • @jimmij: You should make that into an answer. – Dan Jun 8 '16 at 21:31
12
if alias <your_alias_name> 2>/dev/null; then 
  do_something
else 
  do_another_thing; 
fi
| improve this answer | |
  • works great! you will need to hide STDOUT as well if the alias exists. – marinara Jun 22 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.