Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Awimoway

macrumors 68000
Original poster
Sep 13, 2002
1,511
33
California
In my spare time this weekend, I am beginning to teach myself how to use Terminal. There is a really nice tutorial that I am using. But it seems to be a little outdated in places. It's not taking into account that tcsh has been replaced with bash in Panther. (I confess I don't entirely understand what that even means, but at the very least it seems to mean that some Terminal-related file names are different. For example, when the tutorial speaks of .tcsh_history, it is now .bash_history. However there are still some tcsh-related things around, so I'm not sure when to substitute bash for tcsh and when to leave things alone. There may not be an easily comprehensible rule of thumb for a noob like me, but at the very least I would like a little guidance with this section of the tutorial:

Customising Your Command Line Environment


This section is rather advanced, and you may not understand exactly what is going on. Later tutorials will cover such topics in more depth. For now, I present it merely as an exercise for you to try, and not as a full tutorial. You may skip it if you wish.


There is a hidden file in your home directory called '.tcshrc'. This is a configuration file used by the command line and is read each time a new Terminal is started up.


% cat ~/.tcshrc


will view it. You probably don't have one yet. We can make a new one, or add to the end of an existing one, to customise your command line experience.


If you would like the '-i' option permanently applied to cp, rm, and mv, type the following:


% echo "alias cp cp -i \\!\*" >> ~/.tcshrc
% echo "alias mv mv -i \\!\*" >> ~/.tcshrc
% echo "alias rm rm -i \\!\*" >> ~/.tcshrc


'echo' simply echoes what appears between the quotes. '>> ~/.tcshrc' says to add it to the end of the given file instead of echoing to the Terminal. We are adding lines to the '.tcshrc' file. Each is an alias that tells the command line to substitute 'cp', 'mv', and 'rm' with the text that follows.


Start a new Terminal by pressing cmd-N. When a new Terminal starts it reads the commands in '~/.tcshrc', in this case the three aliases. Now all three commands will be replaced with the '-i' versions given in the aliases, and thus always ask for confirmation before a file is overwritten or deleted.


% touch x y z
% rm x y z


If you wish to temporarily override '-i' when issuing a command, use option '-f'.


% rm -f x y z


If you would like the 'trasher' command described above, type:


% echo "alias trash mv \\!\* ~/.Trash" >> ~/.tcshrc


And if you would like 'less' to be the viewer 'man' uses, type:


% echo "setenv PAGER less" >> ~/.tcshrc


Now start a new Terminal window with cmd-N.


Alternatively, you can edit the '.tcshrc' file with 'pico' if you are familiar with it. In this case, add the following lines to the (new) file:


alias cp cp -i \!\*
alias mv mv -i \!\*
alias rm rm -i \!\*
setenv PAGER less
alias trash mv \!\* ~/.Trash


You can reverse this by removing the lines from the file with an editor, or deleting the file if you never had it in the first palace.

I would like to add these safety features, since I'm new at this at don't want to do anything stupid. But I'm not sure about this .tcshrc file. I don't have one right now. Is it fine to name it this? Should it be .bashrc? Am I making any sense? Help would be much appreciated.
 
I hope you'll have lots of fun learning to use Terminal, Awimoway. Before you start adapting the tcsh tutorial for the bash shell, why not just use tcsh instead? If you specify Execute this command (specify complete path): /bin/tcsh in Terminal's preferences, you should get tcsh when you open a Terminal window.
 
Doctor Q said:
I hope you'll have lots of fun learning to use Terminal, Awimoway. Before you start adapting the tcsh tutorial for the bash shell, why not just use tcsh instead? If you specify Execute this command (specify complete path): /bin/tcsh in Terminal's preferences, you should get tcsh when you open a Terminal window.

Cool! Thanks for the tip. Somehow I thought that you couldn't choose your shell and that Panther had bash locked in. This solution works nicely. I understand that bash is more common, but since the differences aren't major and the helpful, free tutorial I've found uses tcsh, I think I'll just stick with it for a while. Thanks again. :)
 
Okay, one other quick question. This one's not essential, but it would be nice to have. How do I create a .tcsh_history file that keeps a record of my doings? Because I only have the bash one and it won't be doing me any good while I use tcsh.
 
Doctor Q said:
I hope you'll have lots of fun learning to use Terminal, Awimoway. Before you start adapting the tcsh tutorial for the bash shell, why not just use tcsh instead? If you specify Execute this command (specify complete path): /bin/tcsh in Terminal's preferences, you should get tcsh when you open a Terminal window.

a better way is to change the global shell using (if your the admin):

Welcome to Darwin!
mymachine:~ encro$ chsh /bin/tcsh

(You only need to type it once to change your shell )
 
Awimoway said:
Okay, one other quick question. This one's not essential, but it would be nice to have. How do I create a .tcsh_history file that keeps a record of my doings? Because I only have the bash one and it won't be doing me any good while I use tcsh.

Welcome to Darwin!
mymachine:~ encro$ touch ~/.tcsh_history
 
encro said:
Welcome to Darwin!
mymachine:~ encro$ touch ~/.tcsh_history
yah..as encro pointed out, the file is already there..touch or cat..
cat ~/.tcsh_history

and one more way to change the default shell. terminal-preferneces there you have a check button called 'execute this command' check it and specify /bin/tcsh in the box below
cheers
 
encro said:
a better way is to change the global shell using (if your the admin):

Welcome to Darwin!
mymachine:~ encro$ chsh /bin/tcsh

(You only need to type it once to change your shell )

Only type in the "chsh /bin/tcsh" part. The rest is stuff on ecro's Terminal screen which will cause an error (user, dir, etc.).
 
After typing in:

chsh /bin/tcsh

I got the following response:

chsh: unknown user: /bin/tcsh

I'm not sure what this means, but it seems that it didn't change the global default shell.

And I've created the ~/.tcsh_history file, but when I'm in tcsh nothing seems to be getting written to it.
 
Awimoway said:
And I've created the ~/.tcsh_history file, but when I'm in tcsh nothing seems to be getting written to it.

Thats because you haven't enabled your history file (it's on by default as a part of bash though which I am using on Panther) but back when I was using Jaguar I had set up a .tcshrc file with the folliwing contents:

Code:
#######################
#      .tcshrc settings file (~/.tcshrc)
#      created by: encro
#######################

set color                       # use color display in the tcsh
set complete = enhance          # Complete case insensitive.
set autolist                    # List autocomplete alternatives when tab pressed
set correct = cmd               # Correct misspelled commands
set savehist = 100              # Save command line history when Terminal closed
set history = 1000              # History remembered is 1000 commands.
set savehist = (1000 merge)     # Save and merge with existing saved commands.

# alias ls ls-F                 # set ls to use the built in tsch color ls

# use a screensaver to animate the desktop, use only on quatz accelerated machines.
alias screensaver /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background

# allow X11 to be started in the same way as Linux.
alias startx /Applications/X11.app/Contents/MacOS/X11

# add any application you want to start from the command line here using an alias.
alias ical "open /Applications/iCal.app"

# set default path statements
setenv PATH /usr/local/bin:$PATH
setenv PATH /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:/Developer/Tools:

and finally this is the ~/.bash_profile I use currently on OS X 10.3 Panther:
Code:
# .bash_profile
#
# Author: encro
# Date Created: 30/10/2003
# Last Edited: 05/02/2004

# The next 3 lines refer to a color bash shell, personally I prefer
# a GreenScreen for Terminal. Uncomment the lines if you like :-)
# export TERM=xterm-color
# export CLICOLOR=true
# export LSCOLORS=dxfxcxdxbxegedabagaca

# Assign my favorite editor to the EDITOR environment variable.
export EDITOR=pico

# I need to assign a printer to use on the command line.
# Use the Printer Queue name as the Environment Variable
# because the Printer Name is completely changeable/editable.
export PRINTER=Stylus_C70

# Some aliases to reduce typing :-)
alias xcode='open -a /Developer/Applications/Xcode.app'
alias ib='open -a /Developer/Applications/Interface\ Builder.app'
alias mysql='/Library/MySQL/bin/mysql'
alias mysqladmin='/Library/MySQL/bin/mysql_config'


# I need to add some extra paths to the Mac OS X defaults
. /sw/bin/init.sh # Fink Path Setup 
PATH=$PATH:/usr/local/bin:/Developer/Tools
# osascript -e 'say "Welcome to Darwin!"'

Hopefully something is of use to you :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.