UNIX & Bash & Aliases

Discussion in 'Mac Programming' started by bobber205, Oct 20, 2006.

  1. bobber205 macrumors 68020

    bobber205

    Joined:
    Nov 15, 2005
    Location:
    Oregon
    #1
    Code:
    alias mysql=//usr/local/mysql/bin/mysq
    When I set that alias, it works only until I exit my current Terminal session.

    Why is that?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    In your home folder (~), make a file named ".bash_profile" and put that line in it. It will then work every time you make a new terminal session.
     
  3. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #3
    Another poster provided to solution. To your question "why is that?": by issuing the command alias mysql=/usr/local/mysql/bin/mysql you are setting the alias for the current shell. If you want to always have an alias available then you need to ensure that the alias is set automatically when an instance of the shell starts. If you create a .bash_profile file in your home directory then every shell command in that file will be executed automatically when a new shell starts. This means that all your aliases will be available.

    By the way, it looks like you are trying to ensure that you can just type mysql to execute /usr/local/mysql/bin/mysql. The reason why you cannot just type mysql to run the command without the alias being set is that the /usr/local/mysql/bin directory is not in the list of paths that are searched to find commands to run. You can fix this by extending the path by using the following command in your .bash_profile file:

    Code:
    export PATH=${PATH}:/usr/local/mysql/bin
    
    You can check the value of the PATH environment variable using the command set or using echo $PATH. You can add multiple new directories to your PATH variable by separating the paths using a ":" character.

    The list of folders in the PATH variable are searched in the order that they are listed. You should only add new directories to the end of the PATH variable. Adding your own directories to the start of the PATH statement opens up a moderate security risk.
     
  4. bobber205 thread starter macrumors 68020

    bobber205

    Joined:
    Nov 15, 2005
    Location:
    Oregon
    #4
    Wow. You guys are great.

    Thanks for the lesson! :D
     

Share This Page