: I am using Korn Shell. I have a c shell file which sets several environment
: variables. People using c shell can source that file. But I am in k shell.
: I tried . filename, but korn shell can't recognize those c shell syntax
: though there is a #!/bin/csh line in that c shell file.
There are a number of scripts, source programs, and documents available
that discuss this particular problem.
ftp.wg.omron.co.jp in /pub/unix-faq/docs/script-vs-env. # "script-vs-env" doc
ftp ftp.uu.net/archive/comp.sources.unix/volume13/korner
korner Convert (some) csh scripts to ksh scripts
ftp ftp.uu.net/archive/comp.sources.unix/volume42/envv/*
envv/patch01 envv - handle env. variables in shell-independent way
envv-1.2/part01 envv-1.2 - handle env. vars in shell-independent way
envv-1.2/patch[1-4] envv-1.2 - handle env. vars in shell-independent way
I recommend that you peruse all the above sources available to you,
especially the first, as it describes the nature of the problem as well
as solving it for a variety of shells.
In addition, here are some scripts that convert one shell's environment
to another's (usually csh to ksh/bash/zsh).
function csh2bash_alias ()
# convert csh alias: eg: alias dir 'ls -al \!* | more'
{ if [ "x$2" = "x" ]
then declare -f $1
else echo $2 | egrep -q '(\!|#)'
if [ $? -eq 0 ]
s/\\!:\([1-9]\)/\"$\1\"/g
s/#/\\#/g')
fi
eval function $1 \(\) "{" command "$comm" "}"
fi
Quote:}
#! /bin/sh
#
# Convert Csh aliases to Bash aliases. Adapted from a similar program
# supplied with zsh.
#
# This is a quick script to convert csh aliases to Bash aliases/functions.
# Pipe the output of csh's alias command through this; it will generate
# a series of alias/function definitions on stdout, suitable for
# processing by bash.
#
# This is not perfect, but it gets most common aliases; it should manage to
# cut down a lot of the busy work.
#
sed -e 's/ (\(.*\))/ \1/' >/tmp/cz$$.1
grep ! /tmp/cz$$.1 >/tmp/cz$$.2
grep -v ! /tmp/cz$$.1 >/tmp/cz$$.3
sed -e "s/'/'"\\\\"''"/g -e 's/^\([^ ]*\) \(.*\)$/alias \1='"'\2'/" \
/tmp/cz$$.3
sed -e 's/![:#]*/$/g' -e 's/^\([^ ]*\) \(.*\)$/\1 () { \2 }/' /tmp/cz$$.2
rm /tmp/cz$$.?
exit 0
#!/bin/ksh
# c2z - environment conversion tool
# Contributed by Bart Schaefer
# (Tweaked a bit by Paul Falstad)
#
# This is a quick script to convert csh aliases to zsh aliases/functions.
# It also converts the csh environment and local variables to zsh. c2z
# uses the csh to parse its own dot-files, then processes csh output to
# convert the csh settings to zsh.
#
# When run as a zsh fuction, c2z runs csh as if it were an interactive
# shell whenever the parent zsh is interactive. When run as a shell
# script, the -i switch can be used to force this behavior.
#
# The -l (login) switch causes csh to run as if it were a login shell.
# This is done "properly" if c2z is used as a zsh function, otherwise
# it's faked by explicitly sourcing .login. Use with caution if your
# .login initializes an X server or does other one-time-only startup
# procedures.
#
# usage:
# c2z [-i] [-l]
#
# You can use this script in your .zshrc or .zlogin files to load your
# regular csh environment into zsh; for example, in .zlogin:
#
# . =(c2z -l)
#
# This is not perfect, but it gets most common aliases and variables.
# It's also rather time-consuming to do this every time you log in.
# However, if you're moving from csh to zsh for the first time, this
# can get you started with a familiar environment right away.
#
# In case your mailer eats tabs, $T is set to expand to a tab.
#
T="`echo x | tr x '\011'`"
# If we're zsh, we can run "- csh" to get the complete environment.
#
MINUS=""
LOGIN=""
INTERACT=""
case "$VERSION" in
zsh*)
case $1 in
-l*) MINUS="-" ;;
-i*) INTERACT="-i" ;;
esac
if [[ -o INTERACTIVE ]]; then INTERACT="-i"; fi
setopt nobanghist
;;
*)
case $1 in
-l*) LOGIN="source ~/.login" ;;
-i*) INTERACT="-i" ;;
esac
;;
esac
( eval $MINUS csh $INTERACT ) <<EOF 2>&1 >/dev/null
$LOGIN
alias >! /tmp/cz$$.a
setenv >! /tmp/cz$$.e
set >! /tmp/cz$$.v
EOF
# save stdin
exec 9<&0
# First convert aliases
exec < /tmp/cz$$.a
# Taken straight from ctoz except for $T and "alias --"
sed -e 's/'"$T"'(\(.*\))/'"$T"'\1/' >/tmp/cz$$.1
grep ! /tmp/cz$$.1 >/tmp/cz$$.2
grep -v ! /tmp/cz$$.1 >/tmp/cz$$.3
sed -e "s/'/'"\\\\"''"/g \
-e 's/^\([^'"$T"']*\)'"$T"'\(.*\)$/alias -- \1='"'\2'/" \
/tmp/cz$$.3
sed -e 's/![:#]*/$/g' \
-e 's/^\([^'"$T"']*\)'"$T"'\(.*\)$/\1 () { \2 }/' \
/tmp/cz$$.2
# Next, convert environment variables
exec < /tmp/cz$$.e
# Would be nice to deal with embedded newlines, e.g. in TERMCAP, but ...
sed -e '/^SHLVL/d' \
-e "s/'/'"\\\\"''"/g \
-e "s/^\([A-Za-z0-9_]*=\)/export \1'/" \
-e "s/$/'/"
# Finally, convert local variables
exec < /tmp/cz$$.v
sed -e 's/'"$T"'/=/' \
-e "s/'/'"\\\\"''"/g \
-e '/^[A-Za-z0-9_]*=[^(]/{
s/=/='"'/"'
s/$/'"'/"'
}' |
sed -e '/^argv=/d' -e '/^cwd=/d' -e '/^filec=/d' -e '/^status=/d' \
-e '/^histchars=/s//HISTCHARS=/' \
-e '/^history=/s//HISTSIZE=/' \
-e '/^home=/s//HOME=/' \
-e '/^ignoreeof=/s/.*/setopt ignoreeof/' \
-e '/^noclobber=/s/.*/setopt noclobber/' \
-e '/^notify=/d' \
-e '/^showdots=/s/.*/setopt globdots/' \
-e '/^savehist=/s//HISTFILE=\~\/.zhistory SAVEHIST=/' \
-e '/^autolist=/s/.*/setopt autolist/' \
-e '/^correct=[cmd]*/s//setopt autocorrect/' \
-e '/^who=/s//WATCHFMT=/'
exec 0<&9
rm /tmp/cz$$.?
exit
-Brian
--
,---. ,---. ,---. ,---. ,---. ,---. ,---.
/ _ \ / _ \ / _ \ / _ \ / _ \ / _ \ / _ \
__,' `.___,' `.___,' `.___,' `.___,' `.___,' `.___,' `.__