如何在bash来设置环境源的CSH脚本 [英] how to source a csh script in bash to set the enviroment
问题描述
我们让Oracle Solaris上运行,并且外壳采用默认CSH。所以,登录脚本设置ORACLE_HOME,ORACLE_SID在csh也。但我不喜欢CSH并希望使用bash做我的工作。所以如何来源CSH登录脚本在bash?
例如,以下是在.cshrc文件。而当使用bash的,我想用这些变量。一种方法是重新复制的变量和使用bash命令,如出口ORACLE_SID = TEST。但这样做需要我们保持文件的两个副本。而当我们更改数据库的名称,或升级数据库,我需要单独maintian bash的login文件。这是很好的只是使用类似
在bash源.cshr,但它不能正常工作。
SETENV ORACLE_SID TEST
SETENV ORACLE_HOME / ORACLE /测试/首页/产品/ 10204
SETENV EPC_DISABLED TRUE
SETENV MANPATH在/ usr /本地/人:在/ usr / share / man的
SETENV编辑器vi
SETENV LD_LIBRARY_PATH $ ORACLE_HOME / lib目录下:在/ usr / SFW / lib中/ 64
SETENV NLS_LANG AMERICAN_AMERICA.UTF8
SETENV NLS_DATE_FORMATDD-MON-RR
在你的〜/ .bashrc中
(或第一个的〜/。在.bash_profile
,〜/ .bash_login文件
和〜/ .profile文件
存在)源此脚本使用像。 〜/斌/ sourcecsh
:
#!/斌/庆典
#这应该是采购的,而不是执行
而阅读CMD VAL变种
做
如果[[$ CMD ==SETENV]]
然后
EVAL出口是$ var = $ VAL
科幻
完成< 〜/ .cshrc中
此版本消除邪恶<$ C $ C>评估:
#!/斌/庆典
#这应该是采购的,而不是执行
#是的,这将在采购采购 - 什么使(U)rcery!
源的/ dev /标准输入&LT; \\
≤(
而阅读CMD VAL变种
做
如果[[$ CMD ==SETENV]]
然后
回声出口是$ var = $ VAL
科幻
完成&LT;的cshrc
)
编辑:
如果没有采购标准输入:
同时读取CMD VAL变种
做
如果[[$ CMD ==SETENV]]
然后
声明-x是$ var = $ VAL
科幻
完成&LT;的cshrc
We have Oracle running on Solaris, and the shell is by default csh. So the login script sets the oracle_home, oracle_sid in csh also. But I don't like csh and want to use bash to do my work. So how to source the csh login script in bash?
e.g, the following is what in the .cshrc file. And when use bash, I'd like use these variables. One way is to copy the variables again and use bash command, such as export ORACLE_SID=TEST. But doing so will require us to maintain two copies of the files. And when we change the database name, or upgrade the database, I need to maintian the bash login file seperately. It's nice to just use something like
source .cshr in bash, but it doesn't work.
setenv ORACLE_SID TEST setenv ORACLE_HOME /oracle/TEST/home/products/10204 setenv EPC_DISABLED TRUE setenv MANPATH /usr/local/man:/usr/share/man setenv EDITOR vi setenv LD_LIBRARY_PATH $ORACLE_HOME/lib:/usr/sfw/lib/64 setenv NLS_LANG AMERICAN_AMERICA.UTF8 setenv NLS_DATE_FORMAT "DD-MON-RR"
In your ~/.bashrc
(or the first of ~/.bash_profile
, ~/.bash_login
, and ~/.profile
that exists) source this script using something like . ~/bin/sourcecsh
:
#!/bin/bash
# This should be sourced rather than executed
while read cmd var val
do
if [[ $cmd == "setenv" ]]
then
eval "export $var=$val"
fi
done < ~/.cshrc
This version eliminates the evil eval
:
#!/bin/bash
# This should be sourced rather than executed
# yes, it will be sourcing within sourcing - what so(u)rcery!
source /dev/stdin < \
<(
while read cmd var val
do
if [[ $cmd == "setenv" ]]
then
echo "export $var=$val"
fi
done < cshrc
)
Edit:
Without sourcing stdin:
while read cmd var val
do
if [[ $cmd == "setenv" ]]
then
declare -x "$var=$val"
fi
done < cshrc
这篇关于如何在bash来设置环境源的CSH脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!