On 27 Feb 2000, in message <[EMAIL PROTECTED]>
  Hidong Kim <[EMAIL PROTECTED]> wrote:
| Thanks for the help Cameron.  I've attached the script.  The script
| contains both the original csh, which I've commented out, and my sh
| translations following each block of csh.

Most excellent. Let's have a look... Comments and corrections inserted below...

| #!/bin/bash
| #
| #  msi_lic_cshrc
| #
| #  Setup script to be sourced in .cshrc file for all MSI software users
| #  This script setup up the following environment variables necessary 
| #  for proper licensing and license management of MSI Software.  
| #
| #  MSI_LIC_PACK_DIR   Location of License_Pack installation
| #  MSI_LIC_PLATFORM     Platform determination for licensing software
| #  PATH                 Path to licensing tools is added to PATH env variable 
| #  LM_LICENSE_FILE      Path to license files is se 
| #  LM_OVERRIDE          License File Path override used by Quanta & Cerius2
| #  LD_LIBRARY_PATH      Licensing Library path for SGIs
| #
| #
| 
| #
| #Set location of MSI license pack
| #
| #if ($?MSI_LIC_PACK_DIR) then
| #   if (-e $MSI_LIC_PACK_DIR/config/lp_cleanup_bash) then
| #      source $MSI_LIC_PACK_DIR/config/lp_cleanup_bash
| #   endif
| #endif
| 
| if [ -n "$MSI_LIC_PACK_DIR" ]; then
|   if [ -e "$MSI_LIC_PACK_DIR/config/lp_cleanup_bash"]; then

Two things. Not all (in fact, few) test commands have a -e; you want
-f.  Also, test expects all its arguments to be separate words,
including the closing "]" (which is just a word like any other, not
punctuation). So this line should read:

        if [ -f "$MSI_LIC_PACK_DIR/config/lp_cleanup_bash" ]; then

|     source "$MSI_LIC_PACK_DIR/config/lp_cleanup_bash"

"source" is spelt "." in the shell:

        . "$MSI_LIC_PACK_DIR/config/lp_cleanup_bash"

|   fi
| fi
| 
| #setenv MSI_LIC_PACK_DIR /usr/local/cnx2000/cnx2000_linux/License_Pack
| 
| export MSI_LIC_PACK_DIR=/usr/local/cnx2000/cnx2000_linux/License_Pack

The syntax export var=value is not portable shell. Several shells don't
support it. At the command line you can say this (because it's easier
if your shell supports it) but for scripts ou should say:

        MSI_LIC_PACK_DIR=/usr/local/cnx2000/cnx2000_linux/License_Pack
        export MSI_LIC_PACK_DIR

| #
| #Set an alias for resetting environment if necessary
| #
| #alias reset_lic_env \
| #  'source $MSI_LIC_PACK_DIR/msi_lic_cshrc'
| 
| alias reset_lic_env='source $MSI_LIC_PACK_DIR/msi_lic_cshrc'

Aliases are not portable shell either. The nearest you have is shell
functions (which are better than aliases anyway). All post-SysV shells
support functions. This line should read:

        reset_lic_env()
        { . "$MSI_LIC_PACK_DIR/msi_lic_cshrc"
        }

Note the quotes, in case $MSI_LIC_PACK_DIR is weird characters in it.

But it gets even better; the file it's sourcing is plainly a csh file.
So it too needs translating (and renaming from *cshrc to *shrc), or you
must play difficult games like this:

        reset_lic_env()
        { cshrcout=`csh -fc "source $MSI_LIC_PACK_DIR/msi_lic_cshrc"; env`
          eval "$cshrcout"
        }

i.e. run the cshrc script with the csh, then dump the environment
with the env command, which produces shell compatible output.
This approach still has problems - the env command doesn't bother
with any quoting, so spaces and newlines in the environment variables
it reports can still screw things up nastily. You really need to use
a program like my dumpenv script:

        http://www.zip.com.au/~cs/scripts/dumpenv

with the -f option. Any there are more complications; if the cshrc
emits cheery messages like "Resetting $VAR now!" like many people seem
to put in their rc files (never imagining they will be run by a program
as a subcomponent) then that output will also be part of the stuff
which comes out of the ``, and will screw up the eval.  You want to to
funny redirections of stdout for the duration of the "source ..." bit.
In the shell this would be easy:

        exec 3>&1 1>/dev/null
        . "$MSI_LIC_PACK_DIR/msi_lic_cshrc"
        exec 1>&3 3>&-
        dumpenv -f

but the csh is really incapacitated about I/O. I can't think, off hand,
if there's any way to say the about in csh, so your "csh -cf"
incantation may have to stay as I have it about, and you'll have to
weed out any evil cshrc files which emit progress messages. (These are
called "plugs" in the Taxonomy Of Bugs, as they are data with land in
the stream of stuff going down the pipeline and confuse the next stage;
this has a double meaning because often these messages are advertising
plugs for the program, like "Welcome to Acme Widget Generator!").

| #
| #Set MSI_LIC_PLATFORM variable
| #
| #setenv MSI_LIC_PLATFORM `$MSI_LIC_PACK_DIR/bin/lmgetplat`
| #if ($status) then 
| #   echo "ERROR: MSI_LIC_PLATFORM could not be set."
| #endif
| 
| export MSI_LIC_PLATFORM=$($MSI_LIC_PACK_DIR/bin/lmgetplat)
| if [ `echo $MSI_LIC_PLATFORM` ]; then
|   echo "ERROR: MSI_LIC_PLATFORM could not be set."
| fi

Again the $(command) syntax is nonportable. For scripts your should still
generally stick to backticks:

        MSI_LIC_PLATFORM=`$MSI_LIC_PACK_DIR/bin/lmgetplat`
        export MSI_LIC_PLATFORM

To truly match the csh code about you want to say:

        if [ $? != 0 ]; then

To do your

        if [ `echo $MSI_LIC_PLATFORM` ]; then

line you have two problems. Firstly, you should have quoted it in case the
variable $MSI_LIC_PLATFORM has whitespace in it, as otherwise the result
of the `` will be broken into words, breaking the syntax of the test command:

        if [ "`echo $MSI_LIC_PLATFORM`" ]; then

Secondly, it's much faster and more succinct to say:

        if [ -z "$MSI_LIC_PLATFORM" ]; then

with no echo command required.

| #
| # Clear MSI_LIC_PAC_DIR/bin and MSI_LIC_PACK_DIR/exe paths in $PATH
| #
| # IRIX 6.5 & 6.5.1 Desktop startup hangs during login on this line.  Users can 
|uncomment this if necessary to 
| # keep PATH environment clean once they've upgraded to IRIX 6.5.2 or above.
| #
| #set path = \
| #`echo $path | sed "s%$MSI_LIC_PACK_DIR/$MSI_LIC_PLATFORM/exe%%g" | sed 
|"s%$MSI_LIC_PACK_DIR/bin%%g" | sed "s%[ ][ ]*% %g"`

Just for the example, let's suppose this line were active. It's VERY
inefficient.  All those sed commands can be rolled into one, saving
much extra work for the machine:

        PATH=`echo "$PATH" | sed -e "%$MSI_LIC_PACK_DIR/$MSI_LIC_PLATFORM/exe%%g" -e 
"s%$MSI_LIC_PACK_DIR/bin%%g" -e "s%::*%:%g"`
        export PATH

Remarks:

        - $path in the csh is $PATH in the bourne shell and is space
          separated in the csh and colon separated in the bourne shell,
          hence those "[ ]" turned into : above.
          BTW, they had no need to use "[ ]", a plain " " would have done.

        - the use of % chars; in sed (and ed and ex and vi) you can use
          any character to delimit the pattern and replacement strings;
          here they've used %s as these are unlikely to be in a PATH
          string.  An even better approach might be a nonprinting
          character (like ^G) as that's even less likely.

| # 
| # Prepend License Pack bin and exe paths to path variable
| #
| #set msi_lic_bin = $MSI_LIC_PACK_DIR/bin
| #if ( -e $msi_lic_bin) then
| #    set path = ($msi_lic_bin $path)
| #endif
| 
| #set msi_lic_exe = $MSI_LIC_PACK_DIR/$MSI_LIC_PLATFORM/exe
| #if ( -e $msi_lic_exe) then
| #    set path = ($msi_lic_exe $path)
| #endif
| 
| msi_lic_bin=$MSI_LIC_PACK_DIR/bin
| if [ -e $msi_lic_bin ]; then
|   path=$msi_lic_bin:$path
| fi

Again, no -e option to test, and $path should be $PATH. Also, since we're
looking for a directory we can say:

        msi_lic_bin=$MSI_LIC_PACK_DIR/bin
        if [ -d "$msi_lic_bin/." ]; then
          PATH=$msi_lic_bin:$PATH
        fi

Note the quotes again in case $msi_lic_bin has a weird name, and the /.
on the test -d; that follows the symlink if $msi_lic_bin names a
symlink instead of a directory.

| msi_lic_exe=$MSI_LIC_PACK_DIR/$MSI_LIC_PLATFORM/exe
| if [ -e $msi_lic_exe ]; then
|   path=$msi_lic_exe:$path
| fi

Repeat the above.

| #
| #Set LM_LICENSE_FILE path
| #
| #
| #Use LM_OVERRIDE for use by Quanta and Cerius2 software
| #
| #if ($?LM_OVERRIDE) then
| #   setenv LM_LICENSE_FILE "$LM_OVERRIDE"
| #else
| #   source $MSI_LIC_PACK_DIR/config/lp_lmenv_bash
| #endif
| 
| if [ -n "$LM_OVERRIDE" ]; then
|    export LM_LICENSE_FILE="$LM_OVERRIDE"

Again, rewrite as:

        LM_LICENSE_FILE=$LM_OVERRIDE
        export LM_LICENSE_FILE

Note that in a vrible assignment we don't need to worry about double
quotes because unlike commands and their arguments, assignments are not
subject to whitespace interpretation.

| else
|    source $MSI_LIC_PACK_DIR/config/lp_lmenv_bash

Again, say
        . "$MSI_LIC_PACK_DIR/config/lp_lmenv_bash"

| fi
| 
| #Users may uncomment this code to enable a warning message
| #if LM_LICENSE_FILE is not set
| #if !($?NO_TEXT) then
| #   if !($?LM_LICENSE_FILE) then
| #      echo ""
| #      echo "msi_lic_cshrc: LM_LICENSE_FILE not set. "
| #      echo ""
| #   endif
| #endif
| 
| #
| #Set LD_LIBRARY_PATH for SGIs
| #
| #set msi_lic_plat = ""
| #set msi_lic_plat = `echo $MSI_LIC_PLATFORM | egrep irix`
| #if ("$msi_lic_plat" != "") then
| #   source $MSI_LIC_PACK_DIR/config/lp_ldenv_bash
| #endif
| 
| #Unset temporary variables
| unset msi_lic_bin
| unset msi_lic_exe
| unset msi_lic_plat
| 
| status=0

status=0 looks to be a manual setting of the csh $status variable.
In the shell, run a command known to success, like the ":" builtin:

        :

Done.
--
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Fear the government that fears your computer. - Jon Drukman <[EMAIL PROTECTED]>


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to