0

I need to export an environmental variable to run a program. I am able to successfully do that in interactive mode. However, when I try to export an environmental variable as part of a bash shell script, I get this error message:

export: Command not found.

In interactive mode, when I type in the following command, it works.

export GT_DIR=/cluster/home/SD/

But when I include the export command as part of the shell script, it does not work. I.e.,

#!/bin/bash

export GT_DIR=/cluster/home/SD/ 

I get the error message:

export: Command not found. 

When I type in echo $SHELL, I get

/bin/bash

Why is the export command working in interactive mode but not when I try to submit it as a script?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
SD23Nov18
  • 5
  • 1
  • what do you get if you do 'type export' in shell, export is a builtin command in bash – ralz Nov 23 '18 at 21:45
  • you need to source somethingthatexportsvariables so the command is run within the current process. running a different script will only change the environment in that script, which then exits. – thrig Nov 23 '18 at 21:46
  • 4
    How do you run your script? – Cyrus Nov 23 '18 at 21:50
  • 1
    export: Command not found. is exactly the error message that a csh outputs. – Cyrus Nov 23 '18 at 21:52
  • @rAlen when I do type export, I get this: export is a shell builtin – SD23Nov18 Nov 23 '18 at 22:26
  • @thrig not sure I quite follow what I need to do here – SD23Nov18 Nov 23 '18 at 22:29
  • @Cyrus I run my script with #!/bin/bash as the shebang. Does that not ensure that bash is used instead of csh? – SD23Nov18 Nov 23 '18 at 22:30
  • see Cyrus comment, it seems you script is being started with csh and not bash, how are you running the script, which command do you use to start it, not the shebang in the script, but exact command you use to start the script? – ralz Nov 23 '18 at 22:30
  • I'm using qsub script.sh to start it – SD23Nov18 Nov 23 '18 at 22:31
  • see this https://stackoverflow.com/questions/42637131/qsub-is-executing-my-bash-script-in-csh-despite-shebang you are starting it in csh it seems, try using qsub shell_sub -S /bin/bash as mentioned there – ralz Nov 23 '18 at 22:33
  • @ralen thanks very much for your help. I tried qsub script.sh -S /bin/bash but the shell was still /bin/csh. I also tried qsub script.sh -b y /bin/bash but it still ran as /bin/csh. It looks like the shell_start_mode is posix_compliant rather than unix_behavior so the shebang is being ignored. Any thoughts on how to get around this (other than having to ask my administrator to change the question settings)? – SD23Nov18 Nov 23 '18 at 22:50

1 Answers1

-2

It worked once I added -S /bin/bash to the shell script rather than as qsub -S /bin/bash

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
SD23Nov18
  • 5
  • 1