Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all, This, to me, seems like a straightforward script, but for some reason, it's not working. I've just installed Intel Fortran, and before every use, the following command needs ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Location
    South Africa
    Posts
    33

    Question Bash script not working properly


    Hi all,

    This, to me, seems like a straightforward script, but for some reason, it's not working.

    I've just installed Intel Fortran, and before every use, the following command needs to be run in order to load the correct environment variables:

    Code:
    source /opt/intel/bin/compilervars.sh ia32
    Once this has been done, just issuing the command "ifort" returns:

    Code:
    ifort: command line error: no files specified; for help type "ifort -help"
    I've made a simple bash script (loadifort.sh) to run the above command (which I'll put into /usr/local/bin when it works):

    Code:
    #!/bin/bash
    echo "Loading Intel Fortran environment variables"
    source /opt/intel/bin/compilervars.sh ia32
    Should be simple, right? However, once I run this bash script, the "Loading Intel Fortran environment variables" line is printed, no error is reported, but then executing "ifort" shows that the environment variables haven't been loaded:

    Code:
    ifort: command not found
    Other commands, such as "gedit" instead of "source /opt/intel/bin/compilervars.sh ia32", work without a problem.

    Any thoughts on this? Any help would be greatly appreciated!

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,346
    That is because the bash-internal source command can read and execute a file containing variable definitions and sets env variables accordingly for the *calling* shell.

    Your wrapper script also sets the env variables. But only for the script itself.

    What you can do is to add the source command to your ~/.bashrc
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Sep 2009
    Location
    South Africa
    Posts
    33
    Thanks for the reply, Irithori. Adding it to .bashrc works just fine.

    Just for my own education, is it possible at all to use "source" to load env vars for the calling shell, not the script, using the script?

    Also, is this a "source"-specific issue, or are there other commands that I should look out for in future? (I will read through Bash Reference Manual when I get the chance; there is a tonne of stuff to digest, though, so it'll take some time!)

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,346
    No, not possible.

    Your shell can have exported variables, which then can get inherited by subsequent commands,
    but not the other way.

    Which is good
    Imagine, if it was possible that sub processes would be able to set env variables to thhe parent process:
    a) This would be a security problem, because a child process might run with less privileges.
    You do not want, that a regular user can set/overwrite e.g. the PATH variable of root.
    b) Multiple declarations. Child process X and child process Y both set a env variable "foo", but with different values. Which shall be valid for the parent?
    c) Cleanup. There are hundreds of child processes for e.g. the init process, but also for others.
    If there was an "upstream inheritance", the parents would be flooded with variables, that they do not even need.
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Sep 2009
    Location
    South Africa
    Posts
    33
    Ah, OK, I see your point!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •