diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 06:17:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 06:17:24 +0000 |
commit | 9d8085074991d5c0a42d6fc96a2d1a3ee918aad1 (patch) | |
tree | c85bca1e6c11eb872edfc64c524d20f2b7e3307b /examples/misc | |
parent | Initial commit. (diff) | |
download | bash-70baf9b08adef67074da9e233fa847220a474b78.tar.xz bash-70baf9b08adef67074da9e233fa847220a474b78.zip |
Adding upstream version 5.1.upstream/5.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/misc')
-rwxr-xr-x | examples/misc/aliasconv.bash | 44 | ||||
-rwxr-xr-x | examples/misc/aliasconv.sh | 42 | ||||
-rwxr-xr-x | examples/misc/cshtobash | 139 |
3 files changed, 225 insertions, 0 deletions
diff --git a/examples/misc/aliasconv.bash b/examples/misc/aliasconv.bash new file mode 100755 index 0000000..22a0447 --- /dev/null +++ b/examples/misc/aliasconv.bash @@ -0,0 +1,44 @@ +#! /bin/bash +# +# aliasconv.bash - convert csh aliases to bash aliases and functions +# +# usage: aliasconv.bash +# +# Chet Ramey +# chet@po.cwru.edu +# +trap 'rm -f $TMPFILE' 0 1 2 3 6 15 + +TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1 + +T=$'\t' + +cat << \EOF >$TMPFILE +mkalias () +{ + case $2 in + '') echo alias ${1}="''" ;; + *[#\!]*) + comm=$(echo $2 | sed 's/\!\*/"$\@"/g + s/\!:\([1-9]\)/"$\1"/g + s/#/\#/g') + echo $1 \(\) "{" command "$comm" "; }" + ;; + *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':g")\' ;; + esac +} +EOF + +# the first thing we want to do is to protect single quotes in the alias, +# since they whole thing is going to be surrounded by single quotes when +# passed to mkalias + +sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE + +$BASH $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \ + -e 's/\$term/\$TERM/g' \ + -e 's/\$home/\$HOME/g' \ + -e 's/\$user/\$USER/g' \ + -e 's/\$prompt/\$PS1/g' + +exit 0 diff --git a/examples/misc/aliasconv.sh b/examples/misc/aliasconv.sh new file mode 100755 index 0000000..fe975d6 --- /dev/null +++ b/examples/misc/aliasconv.sh @@ -0,0 +1,42 @@ +#! /bin/bash +# +# aliasconv.sh - convert csh aliases to bash aliases and functions +# +# usage: aliasconv.sh +# +# Chet Ramey +# chet@po.cwru.edu +# +trap 'rm -f $TMPFILE' 0 1 2 3 6 15 +TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1 +T=' ' + +cat << \EOF >$TMPFILE +mkalias () +{ + case $2 in + '') echo alias ${1}="''" ;; + *[#\!]*) + comm=`echo $2 | sed 's/\\!\*/"$\@"/g + s/\\!:\([1-9]\)/"$\1"/g + s/#/\#/g'` + echo $1 \(\) "{" command "$comm" "; }" + ;; + *) echo alias ${1}=\'`echo "${2}" | sed "s:':'\\\\\\\\'':"`\' ;; + esac +} +EOF + +# the first thing we want to do is to protect single quotes in the alias, +# since they whole thing is going to be surrounded by single quotes when +# passed to mkalias + +sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE + +sh $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \ + -e 's/\$term/\$TERM/g' \ + -e 's/\$home/\$HOME/g' \ + -e 's/\$user/\$USER/g' \ + -e 's/\$prompt/\$PS1/g' + +exit 0 diff --git a/examples/misc/cshtobash b/examples/misc/cshtobash new file mode 100755 index 0000000..ce49bfc --- /dev/null +++ b/examples/misc/cshtobash @@ -0,0 +1,139 @@ +#! /bin/bash +# +# cshtobash - convert csh aliases, environment variables, and variables to +# bash equivalents +# +# usage: cshtobash [filename] +# +# If filename is given, that file is sourced. Note that csh always +# sources .cshrc. To recreate your csh login environment, run +# `cshtobash ~/.login'. +# +# Inspired by (and some borrowed from) a similar program distributed with +# zsh-3.0. +# +# Chet Ramey +# chet@po.cwru.edu +# +trap 'rm -f $TMPFILE1 $TMPFILEa $TMPFILEe $TMPFILEv $TMPFILEco $TMPFILEci' 0 1 2 3 6 15 + +{ TMPFILE1=$(mktemp -t cb.1.XXXXXX) && + TMPFILEa=$(mktemp -t cb.a.XXXXXX) && + TMPFILEe=$(mktemp -t cb.e.XXXXXX) && + TMPFILEv=$(mktemp -t cb.v.XXXXXX) && + TMPFILEco=$(mktemp -t cshout.XXXXXX) && + TMPFILEci=$(mktemp -t cshin.XXXXXX) +} || exit 1 + + +T=$'\t' + +SOURCE="${1:+source $1}" + +cat << EOF >$TMPFILEci +$SOURCE +alias >! $TMPFILEa +setenv >! $TMPFILEe +set >! $TMPFILEv +EOF + +# give csh a minimal environment, similar to what login would provide +/usr/bin/env - USER=$USER HOME=$HOME PATH=/usr/bin:/bin:/usr/ucb:. TERM=$TERM SHELL=$SHELL /bin/csh -i < $TMPFILEci > $TMPFILEco 2>&1 + +# First convert aliases + +cat << \EOF >$TMPFILE1 +mkalias () +{ + case $2 in + '') echo alias ${1}="''" ;; + *[#\!]*) + comm=$(echo $2 | sed 's/\!\*/"$\@"/g + s/\!:\([1-9]\)/"$\1"/g + s/#/\#/g') + echo $1 \(\) "{" command "$comm" "; }" + ;; + *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':")\' ;; + esac +} +EOF + +sed "s/^\([a-zA-Z0-9_]*\)$T\(.*\)$/mkalias \1 '\2'/" < $TMPFILEa >>$TMPFILE1 + +echo '# csh aliases' +echo + +$BASH $TMPFILE1 | sed -e 's/\$cwd/\$PWD/g' \ + -e 's/\$term/\$TERM/g' \ + -e 's/\$home/\$HOME/g' \ + -e 's/\$user/\$USER/g' \ + -e 's/\$prompt/\$PS1/g' + +# Next, convert environment variables +echo +echo '# csh environment variables' +echo + +# Would be nice to deal with embedded newlines, e.g. in TERMCAP, but ... +sed -e '/^SHLVL/d' \ + -e '/^PWD/d' \ + -e "s/'/'"\\\\"''"/g \ + -e "s/^\([A-Za-z0-9_]*=\)/export \1'/" \ + -e "s/$/'/" < $TMPFILEe + +# Finally, convert local variables +echo +echo '# csh variables' +echo + +sed -e 's/'"$T"'/=/' \ + -e "s/'/'"\\\\"''"/g \ + -e '/^[A-Za-z0-9_]*=[^(]/{ + s/=/='"'/"' + s/$/'"'/"' + }' < $TMPFILEv | +sed -e '/^argv=/d' -e '/^cwd=/d' -e '/^filec=/d' -e '/^status=/d' \ + -e '/^verbose=/d' \ + -e '/^term=/d' \ + -e '/^home=/d' \ + -e '/^path=/d' \ + -e '/^user=/d' \ + -e '/^shell=/d' \ + -e '/^cdpath=/d' \ + -e '/^mail=/d' \ + -e '/^home=/s//HOME=/' \ + -e '/^prompt=/s//PS1=/' \ + -e '/^histfile=/s//HISTFILE=/' \ + -e '/^history=/s//HISTSIZE=/' \ + -e '/^savehist=$/s//HISTFILESIZE=${HISTSIZE-500}/' \ + -e '/^savehist=/s//HISTFILESIZE=/' \ + -e '/^ignoreeof=$/s/^.*$/set -o ignoreeof # ignoreeof/' \ + -e '/^ignoreeof=/s//IGNOREEOF=/' \ + -e '/^noclobber=/s/^.*$/set -C # noclobber/' \ + -e '/^notify=/s/^.*$/set -b # notify/' \ + -e '/^noglob=/s/^.*$/set -f # noglob/' \ + + +# now some special csh variables converted to bash equivalents +echo +echo '# special csh variables converted to bash equivalents' +echo + +sed -e 's/'"$T"'/=/' < $TMPFILEv | +grep "^cdpath=" | +sed 's/(// + s/ /:/g + s/)// + s/cdpath=/CDPATH=/' + + +sed -e 's/'"$T"'/=/' < $TMPFILEv | +grep "^mail=" | +sed 's/(// + s/ /:/g + s/)// + s/mail=/MAILPATH=/' | +sed -e 's/MAILPATH=\([0-9][0-9][^:]*\)$/MAILCHECK=\1/' \ + -e 's/MAILPATH=\([0-9][0-9][^:]*\):\(.*\)/MAILCHECK=\1 MAILPATH=\2/' + +exit 0 |