Path: utzoo!utgpu!watserv1!watmath!att!pacbell!pacbell.com!ames!ucsd!usc!sdd.hp.com!hp-pcd!hpfcso!hpfcdc!pbm From: pbm@hpfcdc.HP.COM (Peter McLain) Newsgroups: comp.sys.apollo Subject: Re: Korn shell, mailing lists Message-ID: <8570002@hpfcdc.HP.COM> Date: 9 Jul 90 23:32:04 GMT References: <9007061658.AA23939@fermat.Mayo.edu> Organization: HP Ft. Collins, Co. Lines: 47 >I am starting to write korn shell scripts. I would like to disable the >execution of the file pointed to by the ENV parameter when entering the >script. How is this done? You can turn off the processing of the ENV file for non-interactive shells with the following in your ~/.profile: export ENV='${FILE[(_$-=1)+(_=0)-(_$-!=_${-%%*i*})]}' export FILE=$HOME/.envfile The idea is that ${FILE[0]} = "$HOME/.envfile" and ${FILE[1]} = "". ENV evaluates to the former for interactive shells and the latter for non-interactive shells. The parameter "-" will contain an 'i' for an interactive shell (try "echo $-" in a shell script and at the prompt). All the work is done in the subscript to FILE in the first line above: (_$-=1) set parameter named _$- to 1 (e.g., set _ism=1 for an interactive shell and set _h=1 for a non-interactive shell). (_=0) set parameter named _ to 0 (we need this since we may reference $_ in the next step). (_$-!=_${-%%*i*}) "${-%%*i*}" evaluates to "" if $- contains an 'i', and to $- otherwise. For an interactive shell the check is if "_$-" is NOT the same as "_$-" (false) and for a non-interactive shell the check is if "_$-" is not the same as "_" (true). So this evaluates to 1 (false) for interactive shells, and 0 (true) for non-interactive shells. So for interactive shells you get: ${FILE[1+0-1]} = ${FILE[0]} = $HOME/.envfile and for non-interactive shells you get: ${FILE[1+0-0]} = ${FILE[1]} = "" --------------------- Peter McLain Hewlett-Packard 3404 East Harmony Road pbm%hpfclg@hplabs.HP.COM Fort Collins UUCP: hplabs!hpfcla!pbm CO 80525-9599