2

I was thinking of making a new alias but it seemed like something that might be defined (aliasing git status to status yes I am that lazy.)

I tried running status in terminal (Ubuntu Precise) and the job name isn't defined. Is there anything else I should check before go ahead and make the alias? Is there any defined practice or am I being paranoid?

3

Attempting to run the command does work. There are ways of checking for aliases only but trying to run it is better since that will also find functions, binaries and scripts as well. However, this can be risky in cases where a program exists and does something you don't want when run without arguments.

If you want to check for aliases only, use alias:

alias | grep status

A better approach, which will also find any type of executable as well as aliases, is type:

$ type status
$ type status
bash: type: status: not found
  • 2
    I think type is the correct thing to do here; it tells you what exactly the thing is (if it exists), and also sidesteps the issue of potential misbehaving binaries that might do something you don't want if invoked with no arguments. – Tom Hunt Oct 19 '15 at 20:09
  • @TomHunt good point. I hadn't considered the posibility of misbehaving aliases. – terdon Oct 19 '15 at 20:47
3

The alias command will exit with status 0 and output the definition of the named alias:

$ alias ls
alias ls='ls -G'
$ echo $?
0

If the alias is not defined, an error is printed to standard error and alias exits with status 1:

$ alias foo
bash: alias: foo: not found
$ echo $?
1 
1

The command alias show all defined alias. Then can use grep to check if the new alias you want to define it is being used.

alias | grep 'your_new_alias_name'

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.