 |
 |
Getting aliases to "stick"
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status:
Offline
|
|
I'm having trouble figuring out how to get aliases to "stick" in new terminal windows.
I found this thread http://forums.macnn.com/showthread.p...=setting+alias but after trying the suggestions there, still had no luck.
What I want to do is to set these two aliases to be in effect for each new shell:
Code:
alias mysql '/usr/local/mysql/bin/mysql'
alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
Any help would be appreciated.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2003
Location: Santa Barbara
Status:
Offline
|
|
There are different files you can put them in, but I put my aliases in ~/.cshrc.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by bracken:
There are different files you can put them in, but I put my aliases in ~/.cshrc.
That will work.
Back in the day when I had a lot of aliases (about 200!) I kept them in a ~/.aliases file. Then in ~/.cshrc I had a single line for all my aliases:
source .aliases
Not sure which is more efficient or if it really matters... but it helped to keep things organized.
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status:
Offline
|
|
Originally posted by utidjian:
That will work.
Back in the day when I had a lot of aliases (about 200!) I kept them in a ~/.aliases file. Then in ~/.cshrc I had a single line for all my aliases:
source .aliases
Not sure which is more efficient or if it really matters... but it helped to keep things organized.
Not to sound completely ignorant, though I think I am, how exactly would I go about doing the above or just a one file solution?
I'm very new to working in UNIX.
Thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: May 2003
Location: Santa Barbara
Status:
Offline
|
|
Run Terminal (found in the Utilities folder in Applications).
Enter "pico ~/.cshrc" (Pico is an easy to use editor).
Enter your aliases, line by line.
Control-O to save, Control-X to quit.
Enter "source ~/.cshrc" to start using your aliases.
There are different ways to do this, everyone has their preferences.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status:
Offline
|
|
Originally posted by bracken:
Enter "source ~/.cshrc" to start using your aliases.
So then I'll just have to enter the above each time I start a new shell or is there a way that the aliases will work without typing the above?
Thanks for help.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Location: ~/
Status:
Offline
|
|
Once the aliases are in your .cshrc file they will be available to you any time you launch your shell (when you fire up Terminal). Typing the source ~/.cshrc after making changes to it requires the shell to reread its rc file and perform the commands contained inside of it. If you're in the middle of doing something then make a new alias you can type source ~/.cshrc to apply the changes you just made.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status:
Offline
|
|
Originally posted by Graymalkin:
Once the aliases are in your .cshrc file they will be available to you any time you launch your shell (when you fire up Terminal). Typing the source ~/.cshrc after making changes to it requires the shell to reread its rc file and perform the commands contained inside of it. If you're in the middle of doing something then make a new alias you can type source ~/.cshrc to apply the changes you just made.
Hmm....for some reason it does not work for me. I have the ~/.cshrc filed edited but I still can't get it to work until I type source ~/.cshrc. *shrug*
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Location: Up north
Status:
Offline
|
|
Originally posted by shadybirdstan:
Hmm....for some reason it does not work for me. I have the ~/.cshrc filed edited but I still can't get it to work until I type source ~/.cshrc. *shrug*
did you try opening a new window?
any new windows will automagically have the aliases from your .cshrc or whatever, you have to mess around to get an old window to know about the new aliases. Why bother? just restart terminal
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
Ok, there's plenty of answers but no explaination, so let me try.
The default shell the Terminal uses is tcsh (/bin/tcsh). tcsh is an extension of csh that gives you a few extra features. If you look in /bin, you'll also see bash, csh, and zsh, all different shells. For full details on these shells, check their man pages.
When tcsh is started, it first sources the /etc/csh.cshrc file. After doing so, it checks for a .tcshrc then a .cshrc in your home directory and will load only the first one found (personally, all my .tcshrc does is source my .cshrc, then set the prompt).
alias commands (path changes, environment variables, and who knows what else) should be entered here (or, in a file like .aliases that the .cshrc sources). The comment above to 'source ~/.cshrc' only applies after making changes to your .cshrc. A new shell (Terminal window) will automatically load your .cshrc, so you don't have to do this.
pico?? Real geeks use vi. Pseudo geeks use emacs. There, that should piss someone off. ;}
|
|
-Flowers...
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Location: Sunnyvale, CA
Status:
Offline
|
|
Wouldn't it be easier to add something like:
setenv PATH {$PATH}:/usr/local/mysql/bin/
in ~/.login? That would allow you to access all commands in /usr/local/mysql/bin by name.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Status:
Offline
|
|
Originally posted by ryochiji:
Wouldn't it be easier to add something like:
setenv PATH {$PATH}:/usr/local/mysql/bin/
in ~/.login? That would allow you to access all commands in /usr/local/mysql/bin by name.
I'm not 100% up on the ~/.login file (more info is in the tcsh man page), but I think that is just read for the login shell. Opening a new terminal window is probably not considered a login shell, so the ~/.login wouldn't be read. Right idea, wrong file.
|
|
-Flowers...
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
Ok, I'm a bit confused by all this... what exactly is "sourcing " a file ?
Say you do decide to put all your alias commands in a ~/.aliases file....
Then, to make tsch read all the commands and execute them from that file, do you simply put a line in the /.tcshrc that says "source ~/.aliases" ? Will that make the shell go 'subroutine' and look at the ~/.aliases file before doing whatever else in the .tcshrc ?
Thanks unix heads!
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Aug 2002
Status:
Offline
|
|
yes, basicly
the 'source' command will run the commands in the file it is pointed to
open a terminal and type 'man source' for detailed info
--will
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Dec 2001
Location: My own personal purgatory
Status:
Offline
|
|
Not to muddy the waters any further, but I had thought that the "official" place to put tcsh aliases was ~/Library/init/tcsh/aliases.mine ...?
|
|
"A scientist can discover a new star but he cannot make one. He would have to ask an engineer to do it for him."
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
Originally posted by Glennfield:
Not to muddy the waters any further, but I had thought that the "official" place to put tcsh aliases was ~/Library/init/tcsh/aliases.mine ...?
That might be were Apple wants em, but they can bugger off. The standard unix place for _your_ aliases, etc is in your .cshrc file (for csh, tcsh, zsh??). Never been a bash user, but I think they have a .bashrc. (or you can use a .aliases file and source that from your .cshrc)
As for .login, that is only sourced (read in) in the first shell (I believe). A .cshrc is read when any new shell is launched. It is not read in every time it is editted... so in shell #1, if you add an alias to .cshrc
a) shell #1 won't see that alias unless you "source .cshrc"
b) if you launch a new window, shell #2 will see that alias.
Cheers,
Mike
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status:
Offline
|
|
Originally posted by Zim:
That might be were Apple wants em, but they can bugger off.
The way one sets up their shell is a person thing and I wouldn't try to convince anyone to do something they didn't want to do. However, for the benefit of readers that don't know, I want to say that locating aliases in ~/Library/init/tcsh is not something Apple "wants", it's an opportunity they provide. A ~/Library/init/tcsh/aliases.mine file is sourced automatically if you use the tcsh startup scripts in /usr/share/tcsh/examples. These are a battery of scripts written by Wilfredo Sanchez Jr. of MIT in 1990 and they are some of the best designed scripts I've ever read.
The scripts modularize the code, grouping it according to whether or not the shell is a login shell and/or interactive and they set variables to make it easy to determine the state of shell. They set up a decent environment, configure completion and create a beginning set of aliases. Most importantly, they contain a convenient mechanism for extending the scripts without editing them. That's where the ~/Library/init/tcsh directory comes in. Scripts put in the directory and appropriately named will be automatically sourced. That way you can safely extend the scripts. If you make a mistake that keeps the shell from functioning correctly, all you have to do is rename the script and the shell will function like before. Overall, its a very capable and robust construction. I just wanted to extol its virtues for those that don't know.
As a matter of interest, the maintainer of bash at Fink adopted a similar set of scripts to configure that installation. Personally, if I used bash I would use that version just for the scripts. I use zsh and did the same for that shell.
|
|
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2001
Location: Work: NYC Live: NJ
Status:
Offline
|
|
Originally posted by ryochiji:
Wouldn't it be easier to add something like:
setenv PATH {$PATH}:/usr/local/mysql/bin/
in ~/.login? That would allow you to access all commands in /usr/local/mysql/bin by name.
This was the easiest to do and accomplished the job perfectly.
Thanks!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|