bash vs csh(==tcsh) programming: The make*.doc files have a mixture of csh and bash scripting instructions. The typical process to use these scripts is to cut them from the make*.doc file and paste them onto your shell prompt. This document describes how to work with either kind of script from either kind of shell. See also: on-line tcsh help: http://www.techfak.uni-bielefeld.de/rechner/shells/tcsh/top.html on-line bash tutorial: http://www.hypexr.org/bash_tutorial.shtml http://www.faqs.org/docs/bashman/bashref.html#SEC_Top or: 'man bash' for bash man page, 'man tcsh' for tcsh man page The procedure to allow this to work is to create in your HOME directory the appropriate ~/.*shrc file for both shells so that your working environment will be the same in either shell environment. With both sets of definitions in place, using either kind of script can be done by entering the "other" shell when you encounter the "other" shell script instructions, then exit back to your default shell. To enter the "other" shell at your default shell prompt, enter one of the two commands, bash or tcsh: # from bash to csh: [hiram@kk9 /tmp] tcsh # from csh to bash: bash [hiram@kk9 /tmp] It is a good idea to have a different prompt setting to help recognize your shell. When in doubt, do a 'ps -f' and you will see the nest of shells as child processes of each other. bash uses the environment variables PS1 and PS2, csh uses the shell variable: prompt. Your default login shell probably already has one of these files: ~/.bashrc - for bash login shells ~/.cshrc or .tcshrc - for csh or tcsh login shells The complication is that they do not use the same kind of syntax for definitions. You can not simply copy from one to the other. The differences are simple. ==================================================================== SYNTAX differences ==================================================================== 1. Setting environment variables in the ~/.*shrc files: # bash syntax: export CVSROOT=/projects/compbio/cvsroot # csh syntax: setenv CVSROOT /projects/compbio/cvsroot # setting csh shell variables: set prompt = '<%n@%m %c> ' # the bash prompt is an environment variable: export PS1='[$LOGNAME@$HOST ${PWD##}] ' *NOTE*: do *not* use white space around the = sign in the bash assignment. If you do not "export" a bash variable, it will not be inherited by sub-shells. See also, programming the bash prompt: http://en.tldp.org/HOWTO/Bash-Prompt-HOWTO/ 2. alias statements are the same in bash and csh alias ma='make HG_WARN=-Wall' 3. if statement syntax is different: # bash syntax: if [ -s /usr/lib/mysql/libmysqlclient.a ]; then export MYSQLINC=/usr/include/mysql export MYSQLLIBS="/usr/lib/mysql/libmysqlclient.a -lz" fi # csh syntax: if( -s /usr/lib/mysql/libmysqlclient.a ) then setenv MYSQLINC /usr/include/mysql/ setenv MYSQLLIBS "/usr/lib/mysql/libmysqlclient.a -lz" endif *NOTE*: You *must* use white space around the [ and before the ] since those symbols are shell built-in commands to bash ! See also: 'man test' for a list of the file compare operators ==================================================================== NOTES: ==================================================================== Actual script files can be run from either shell without difficulty. A bash shell script file begins with a first line: #!/bin/sh A csh shell script file begins with a first line: #!/bin/csh -fe These initial lines are interpreted to specify which shell to use for the script. So, if the script is in a shell, you need do nothing special to operate it. Just run it as a command from your shell prompt. Substitutions: There are too may ways to do this in either shell to do this subject justice. A few pointers: bash and csh have completely different substitution methods to edit strings in variables. For example, csh typically uses the : operator to parse strings: pwd /tmp/test echo $PWD /tmp/test echo $PWD:t test echo $PWD:h /tmp The same head and tail functions in bash are done by the dirname and basename commands: [hiram@hgwdev /tmp/test] echo $PWD /tmp/test [hiram@hgwdev /tmp/test] echo `basename $PWD` test [hiram@hgwdev /tmp/test] echo `dirname $PWD` /tmp Modifying strings in csh: echo $PWD:s/test/testing/ /tmp/testing Modifying strings in bash: [hiram@hgwdev /tmp/test] echo ${PWD/test/testing/} /tmp/testing/ ==================================================================== This file last updated: $Date: 2006/07/25 20:12:51 $