Operating System - HP-UX
1745790 Members
4312 Online
108722 Solutions
New Discussion юеВ

don't want .kshrc to be soured when running a script, please tell me how

 
SOLVED
Go to solution
arking1981
Frequent Advisor

don't want .kshrc to be soured when running a script, please tell me how

Dear all,

I have two servers but with different behaviors, sdb1 and dmc:

In sdb1, whatever script I run, the .kshrc seems to be sourced and exceuted, for example I have a simple script to print "Hello" with debug option enabled as
#! /bin/sh -x

echo "hello"

execute it, I will get
+ export PATH=/usr/sbin:/usr/sbin:/usr/sbin:/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/hparray/bin:/opt/nettladm/bin:/opt/upgrade/bin:/opt/fcms/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/pd/bin:/opt/wbem/bin:/opt/wbem/sbin:/opt/resmon/bin:/opt/firefox:/opt/gnome/bin:/opt/mozilla:/opt/graphics/common/bin:/opt/hpsmh/bin:/opt/perl_32/bin:/opt/perl_64/bin:/usr/sbin/diag/contrib:/opt/sfm/bin:/opt/ssh/bin:/opt/thunderbird:/opt/gwlm/bin:/opt/OSSInstall/bin:/opt/platform7/bin:/opt/TSDCommon/bin:/opt/DataBroker/bin:/opt/a7healthCheck/bin:/opt/stcroamcommon/bin:/opt/ignite/bin:/sbin:/home/root:/sbin:/sbin:/sbin
+ umask 022
+ who am i -u
+ head -n1
+ read junk TTY junk
+ [[ ! -d //.sh_history ]]
+ echo pts/1
+ tr / .
+ export HISTFILE=//.sh_history/pts.1
+ unset junk TTY
+ set -o vi
+ PS1=s7sdb1 #
+ echo hello
hello

but on dmc,
I just get
s7dmc # ./ttest
+ echo hello
hello

Here I don't want .kshrc to be sourced and executed in sdb1. Can anybody tell me how?

I compared the .profile and .kshrc on both servers, and they look exactly similar execept some hostname settings.

Thanks in advance.
Best Regards
Kang

Hello world...
4 REPLIES 4
Dennis Handly
Acclaimed Contributor
Solution

Re: don't want .kshrc to be soured when running a script, please tell me how

>whatever script I run, the .kshrc seems to be sourced and executed

This occurs if ENV is exported with the name of your ~/.kshrc file.

>Here I don't want .kshrc to be sourced and executed in sdb1. Can anybody tell me how?

There is a magic string that you can set ENV so that if it isn't interactive, it expands to empty.
export ENV='${FILE[(_$-=1)+(_=0)-(_$-!=_${-%%*i*})]}'
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1116432
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=823049
arking1981
Frequent Advisor

Re: don't want .kshrc to be soured when running a script, please tell me how

Dear Danis,

I have the same profile settings on both server, but different results for ENV

This server is what I want:
s7dmc # tail /.profile

# Set ENV file to source .kshrc if this is an interactive shell.

export ENV_FILE=/.kshrc
export ENV='${ENV_FILE[ (_$-= 1) + (_ = 0) - (_$- != _${-%%*i*}) ]}'

export ORACLE_HOME=/opt/oracle/product/9.2.0
export PATH=/usr/lbin/sw/bin:/var/adm/sw/sbin:/sbin:/usr/bin:/usr/ccs/bin:/usr/sbin:/usr/lbin/sw:/opt/oracle/product/9.2.0/bin
export TNS_ADMIN=/opt/oracle/product/9.2.0/network/admin
export ORACLE_SID=dmc
s7dmc # echo $ENV_FILE
/.kshrc
s7dmc # echo $ENV
${ENV_FILE[ (_$-= 1) + (_ = 0) - (_$- != _${-%%*i*}) ]}

This is not
s7sdb1 # echo $ENV_FILE
/.kshrc
s7sdb1 # tail /.profile

MAIL=/var/mail/root
# don't export, so only login shell checks.

echo "WARNING: YOU ARE SUPERUSER !!\n"

# Set ENV file to source .kshrc if this is an interactive shell.

export ENV_FILE=/.kshrc
export ENV=${ENV_FILE[ (_$-= 1) + (_ = 0) - (_$- != _${-%%*i*}) ]}
s7sdb1 # echo $ENV_FILE
/.kshrc
s7sdb1 # echo $ENV
/.kshrc

please suggest.
Thanks and Regards
Xie Kang
Hello world...
arking1981
Frequent Advisor

Re: don't want .kshrc to be soured when running a script, please tell me how

Dear Dannis,

Thanks.
Just notice in that line there is no '' in sdb1.

Regards
kang
Hello world...
arking1981
Frequent Advisor

Re: don't want .kshrc to be soured when running a script, please tell me how

clsoe
Hello world...