View Full Version : Aliases not working
b1hgaa88
02-26-2002, 10:56 AM
I followed instructions to set up aliases in my tcsh Shell configuration file (.cshrc) but they are not working. My .cshrc file reads as follows:
[localhost:~] jfwoods% cat .cshrc
source /sw/bin/init.csh
alias quit="logout"
alias cd="cd !*;echo $cwd"
alias home="cd ~"
alias ls="ls -F"
alias pwd="echo $cwd"
alias dir="ls -alg"
None of the above aliases is working. When I open a new Terminal (or type "rehash") and then "alias" I just get the built-in aliases. What gives?
My second question is that I read somewhere that I should have a .tcshrc file but I don't have such a file. What is the difference between a .tcshrc file and a .cshrc file?
I am a single user on an iMac using Mac OS 10.1.3
Thanks for any help
mervTormel
02-26-2002, 11:13 AM
which instructions? you've got a lot of problems with those aliases.
they are of the wrong form for tcsh. they should be:
alias name 'value'
this alias won't work even then:
alias cd="cd !*;echo $cwd"
the !* arg needs to be escaped, that is, masked from being evaluated while the alias is being defined.
it is considered bad form to redefine system commands, that is, there is already a cd command that you will mask by this alias.
perhaps consider:
alias zcd 'cd \!* ; echo $cwd'
at this point, don't worry about .tcshrc, your .cshrc will work (until you create a .tcshrc)
b1hgaa88
02-26-2002, 12:20 PM
Oh! The "instructions" are those of Deborah S. Ray and Eric J. Ray on page 157 of their book "UNIX Visual Quickstart Guide" published by Peachpit Press. The relevant section is entitled, "Setting aliases with alias" in Chapter 8 ("Configuring your UNIX Environment").
I was also wondering whether my .cshrc file was in the right place. Mine is directly in:
/Users/username/.cshrc
but others appear to have it in:
/Users/username/Library/init/tcsh/.cshrc
b1hgaa88
02-26-2002, 12:33 PM
Just noticed that the UNIX Visual Guide is talking about the csh Shell (which I presumed would work for the tcsh Shell).
How then do I proceed (or "mask"). Is that the purpose of the "\" in your suggestion about making the "zcd" alias? Does this do the masking?
I have also been reading the README and other files (rc; login; logout) in the:
/usr/share/init/tcsh
folder, and they tell me to create five other files. But do I need all these files if I'm just a single user on a home machine (i.e. not on a network)?
mervTormel
02-26-2002, 12:39 PM
debbie and eric's book is probably okay, but you need to interpret their instructions for your shell.
it looks like they are using the bourne shell (sh) family, and you are using tcsh (csh family). they have _some_ different syntax.
you .cshrc is in the right place.
read the following for more info on tcsh startup files...
% cat /usr/share/init/tcsh/README
Also, I will suggest you read this thread :
http://forums.macosxhints.com/showthread.php?s=&threadid=792
Maybe it helps.
Cheers...
mervTormel
02-26-2002, 03:23 PM
Originally posted by b1hgaa88
Just noticed that the UNIX Visual Guide is talking about the csh Shell (which I presumed would work for the tcsh Shell).
How then do I proceed (or "mask"). Is that the purpose of the "\" in your suggestion about making the "zcd" alias? Does this do the masking?
...But do I need all these files if I'm just a single user on a home machine (i.e. not on a network)?
csh aliases do work in tcsh, but those aliases you had were certainly bourne shell (sh) aliases, not csh, so debbie and eric are prolly enumerating both shell families.
re: mask, what i meant was that there is a perfectly good, functional cd command builtin to the shell. if you define alias cd, you mask (defeat) the functionality of the builtin cd command.
the backslash in the alias "value" is to prevent the shell interpreter from evaluating the special variable !* at alias definition time. try it both ways, one with the \ and one without and see your results.
re: the tcsh startup mechanism in the readme has little relationship with single user vs. network. note i said "little". there is some relationship, but follow the instructions and count on seeing a tunnel at the end of the light later. keep diggin'
b1hgaa88
02-26-2002, 06:34 PM
Merv, yes - you are right. The Rays use the Bourne Shell family as the example. A trifle confusing because they imply that the example would go for bash, ksh and csh shells, using the right file name (.cshrc in the case of csh).
I have read the README you suggested and have followed the process through. It suggests putting the alias instructions into aliases.mine (i.e. instead of .cshrc), but if my syntax is wrong where can I find out what the right syntax is? I am glad I haven't so far 'masked' the built-in cd alias, and will note your suggestion. But that light at the end of the tunnel is not yet in sight.
Sao - thanks. I have the thread you suggest and am in the process of digesting it (also one on a fink error message).
Will be back!
mervTormel
02-26-2002, 07:23 PM
b1,
you can read all about tcsh in the man pages
% man tcsh
also, follow examples. what do the aliases in /usr/share/init/tcsh/aliases look like?
alias name 'value'
that's the format for tcsh aliases, e.g.
alias ztp 'top -u -s3 10'
% ztp
blah blah blah
b1hgaa88
02-26-2002, 10:38 PM
Thanks Merv; sao. Checked my tcsh/aliases file and went from there. All now works O.k.
Again. Many thanks for your help.
mervTormel
02-26-2002, 11:23 PM
good. yeah, i'm afraid it's going to be "a trifle confusing" at the beginning. even towards the middle. ah, hell, it's been several years and i'm still confused. it takes a bit of a tinkerer to persevere and decipher the code, but sweat it out, turn the corner, go towards the light, speak in bumper-sticker. it gets clearer.
dig in to the docs, the man pages, and some books. when you hit a wall, post your questions here and some gentle soul or crusty bastard (it takes all kinds) will try and answer.
regards, -mt
--
if it were easy, we wouldn't call it code.
I must admit I don't have a clue, I'm still in the dark here.
But it's very interesting.
Cheers...
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.