How can I make my csh aliases work when I convert to bash?

How can I make my csh aliases work when I convert to bash?


Bash uses a different syntax to support aliases than csh does.
The details can be found in the documentation. We have provided
a shell script which does most of the work of conversion for you;
this script can be found in ./examples/misc/aliasconv.sh. Here is
how you use it:

Start csh in the normal way for you. (e.g., `csh')

Pipe the output of `alias' through `aliasconv.sh', saving the
results into `bash_aliases':

alias | bash aliasconv.sh >bash_aliases

Edit `bash_aliases', carefully reading through any created
functions. You will need to change the names of some csh specific
variables to the bash equivalents. The script converts $cwd to
$PWD, $term to $TERM, $home to $HOME, $user to $USER, and $prompt
to $PS1. You may also have to add quotes to avoid unwanted
expansion.

For example, the csh alias:

alias cd 'cd \!*; echo $cwd'

is converted to the bash function:

cd () { command cd "$@"; echo $PWD ; }

The only thing that needs to be done is to quote $PWD:

cd () { command cd "$@"; echo "$PWD" ; }

Merge the edited file into your ~/.bashrc.

There is an additional, more ambitious, script in
examples/misc/cshtobash that attempts to convert your entire csh
environment to its bash equivalent. This script can be run as
simply `cshtobash' to convert your normal interactive
environment, or as `cshtobash ~/.login' to convert your login
environment.



Home FAQ