3 # cshtobash - convert csh aliases, environment variables, and variables to
6 # usage: cshtobash [filename]
8 # If filename is given, that file is sourced. Note that csh always
9 # sources .cshrc. To recreate your csh login environment, run
10 # `cshtobash ~/.login'.
12 # Inspired by (and some borrowed from) a similar program distributed with
18 trap 'rm -f $TMPFILE1 $TMPFILEa $TMPFILEe $TMPFILEv $TMPFILEco $TMPFILEci' 0 1 2 3 6 15
20 { TMPFILE1
=$
(mktemp
-t cb
.1.XXXXXX
) &&
21 TMPFILEa
=$
(mktemp
-t cb.a.XXXXXX
) &&
22 TMPFILEe
=$
(mktemp
-t cb.e.XXXXXX
) &&
23 TMPFILEv
=$
(mktemp
-t cb.v.XXXXXX
) &&
24 TMPFILEco
=$
(mktemp
-t cshout.XXXXXX
) &&
25 TMPFILEci
=$
(mktemp
-t cshin.XXXXXX
)
31 SOURCE
="${1:+source $1}"
33 cat << EOF >$TMPFILEci
40 # give csh a minimal environment, similar to what login would provide
41 /usr
/bin
/env
- USER
=$USER HOME
=$HOME PATH
=/usr
/bin
:/bin
:/usr
/ucb
:. TERM
=$TERM SHELL
=$SHELL /bin
/csh
-i < $TMPFILEci > $TMPFILEco 2>&1
43 # First convert aliases
45 cat << \EOF
>$TMPFILE1
49 '') echo alias ${1}="''" ;;
51 comm=$
(echo $2 |
sed 's/\!\*/"$\@"/g
52 s/\!:\([1-9]\)/"$\1"/g
54 echo $1 \
(\
) "{" command "$comm" "; }"
56 *) echo alias ${1}=\'$
(echo "${2}" |
sed "s:':'\\\\'':")\' ;;
61 sed "s/^\([a-zA-Z0-9_]*\)$T\(.*\)$/mkalias \1 '\2'/" < $TMPFILEa >>$TMPFILE1
66 $BASH $TMPFILE1 |
sed -e 's/\$cwd/\$PWD/g' \
67 -e 's/\$term/\$TERM/g' \
68 -e 's/\$home/\$HOME/g' \
69 -e 's/\$user/\$USER/g' \
70 -e 's/\$prompt/\$PS1/g'
72 # Next, convert environment variables
74 echo '# csh environment variables'
77 # Would be nice to deal with embedded newlines, e.g. in TERMCAP, but ...
80 -e "s/'/'"\\\\"''"/g \
81 -e "s/^\([A-Za-z0-9_]*=\)/export \1'/" \
82 -e "s/$/'/" < $TMPFILEe
84 # Finally, convert local variables
86 echo '# csh variables'
89 sed -e 's/'"$T"'/=/' \
90 -e "s/'/'"\\\\"''"/g \
91 -e '/^[A-Za-z0-9_]*=[^(]/{
95 sed -e '/^argv=/d' -e '/^cwd=/d' -e '/^filec=/d' -e '/^status=/d' \
104 -e '/^home=/s//HOME=/' \
105 -e '/^prompt=/s//PS1=/' \
106 -e '/^histfile=/s//HISTFILE=/' \
107 -e '/^history=/s//HISTSIZE=/' \
108 -e '/^savehist=$/s//HISTFILESIZE=${HISTSIZE-500}/' \
109 -e '/^savehist=/s//HISTFILESIZE=/' \
110 -e '/^ignoreeof=$/s/^.*$/set -o ignoreeof # ignoreeof/' \
111 -e '/^ignoreeof=/s//IGNOREEOF=/' \
112 -e '/^noclobber=/s/^.*$/set -C # noclobber/' \
113 -e '/^notify=/s/^.*$/set -b # notify/' \
114 -e '/^noglob=/s/^.*$/set -f # noglob/' \
117 # now some special csh variables converted to bash equivalents
119 echo '# special csh variables converted to bash equivalents'
122 sed -e 's/'"$T"'/=/' < $TMPFILEv |
130 sed -e 's/'"$T"'/=/' < $TMPFILEv |
135 s/mail=/MAILPATH=/' |
136 sed -e 's/MAILPATH=\([0-9][0-9][^:]*\)$/MAILCHECK=\1/' \
137 -e 's/MAILPATH=\([0-9][0-9][^:]*\):\(.*\)/MAILCHECK=\1 MAILPATH=\2/'