How can I check in my bashrc if an alias was already set

If you just want to make sure that the alias doesn’t exist, just unalias it and redirect its error to /dev/null like this:

unalias foo 2>/dev/null

You can check if an alias is set with something like this:

alias foo >/dev/null 2>&1 && echo "foo is set as an alias" || echo "foo is not an alias"

As stated in the manpage:

For each name in the argument list for which no  value  is  sup-
plied,  the  name  and  value  of  the  alias is printed.  Alias
returns true unless a name is given for which no alias has  been
defined.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)