General discussion

  • Creator
    Topic
  • #2076897

    Shell Scripts and Exporting

    Locked

    by chalo ·

    Hello, I am new to Linux and we plan to develop application servers in Linux. Currently, I am trying to get Weblogic’s Javabean container and Console running from a script. I can run the Console and the container from the command line no problem however, I am having difficulty getting the shell scripts to work. Help?

    I mean, I can not even get the weblogic .bash_profile for the user I set up to export the PS1 variable I assigned or any other. Also, Weblogic has a setEnv.sh script to set up and export some more special variables such as JAVA_HOME but after you run the script “sh setEnv.sh” and then type “echo $Java_Home” nothing. I have already made sure weblogic owns the file,directory and permissions are set 755. This can’t be rocket science and the funny thing is if I assign variables and export them in etc/profile, they sometimes work with no problem but I do not want to clutter etc/profile if I do not have to or, is there where this stuff should go anyway. Please tellme what is going wrong with my shell scripts? P.S. I am running Red Hat 6.2

All Comments

  • Author
    Replies
    • #3785521

      Shell Scripts and Exporting

      by tastin ·

      In reply to Shell Scripts and Exporting

      I played around with a quick test file and found that typing “source shell.sh” set the variables I placed inside them in my local enviroment. I’ll keep checking this out. I haven’t messed with shell scripts in a while. Hope this helps.

    • #3785465

      Shell Scripts and Exporting

      by hasse mcse/brainbench ·

      In reply to Shell Scripts and Exporting

      Hi!

      I’m not sure about this, but in order to get variables to work you can either user source a .sh file as stated above or use the users .bashrc and .profile.
      .bashrc in users home dir is used if that users logs in and has defualt shell bash.
      If you instead have #!/bin/sh at the top of your start and stop scripts then this shell won’t read .bashrc .profile or any other startupfiles.

      So this menas you’ll have to set them in the shell script.

      /Hasse

    • #3787635

      Shell Scripts and Exporting

      by jpereira ·

      In reply to Shell Scripts and Exporting

      Your problem is that when you run a program or script from another script, Unix actually creates a new process which is a complete duplicate of the original process (including its environment) and runs the new script in that. Any changes to the environment are made to the duplicate environment which goes away when the new script exits. If you want to have variables change as a result of running a script, you need to “source” the script i.e. run it without creating a new process. This is done in a korne shell as follows: “. your_script” (note the leading “.”). I think the same thing will work in bash.

    • #3785953

      Shell Scripts and Exporting

      by zbrain75 ·

      In reply to Shell Scripts and Exporting

      jpereia@sendmail.com is correct. I made the following testfile called test1:
      #!/bin/bash
      export MYVAR=”this is a test”

      If it is run from the command line as follows:
      test1
      the variable is not set, but if run as follows:
      . test1
      You can type “echo $MYVAR” and see the variable and also see it with the “env” command.

      The problem with your PS1 variable is that in Redhat, the user’s $HOME/.bashrc script runs the /etc/bashrc file which resets the PS1 variable to a preset value. I recommend commenting out the call from $HOME/.bashrc to /etc/bashrc, and setting the PS1 var in the user’s .bash_profile script. See the Linux tip at http://ctdp.homestead.com/files/os/linux/tips/index.html Tip#2 The same info may be more accessable at http://ctdp.tripod.com/os..

    • #3863465

      Shell Scripts and Exporting

      by chalo ·

      In reply to Shell Scripts and Exporting

      This question was auto closed due to inactivity

Viewing 4 reply threads