我安装了一个社区软件,它需要在特定目录中运行一些 bash 脚本。但是,如果我这样做,就会出现错误消息:
"ERROR: Command: 'source /usr/bin/bash && module list' failed with error '/bin/sh: line 0: source: /usr/bin/bash: cannot execute binary file' from dir '/home/xxx/example1'.
如果我将目录更改为/usr/bin
,它就可以工作。问题是我必须在 目录中运行脚本example1
。我尝试将 /usr/bin 添加到 PATH 中,但没有成功。如有任何意见,我们将不胜感激。谢谢。
Update1:这里是软件用来生成shell脚本的python脚本:
def make_env_mach_specific_file(self, shell, case, output_dir=''):
"""Writes .env_mach_specific.sh or .env_mach_specific.csh
Args:
shell: string - 'sh' or 'csh'
case: case object
output_dir: string - path to output directory (if empty string, uses current directory)
"""
module_system = self.get_module_system_type()
sh_init_cmd = self.get_module_system_init_path(shell)
sh_mod_cmd = self.get_module_system_cmd_path(shell)
lines = ["# This file is for user convenience only and is not used by the model"]
lines.append("# Changes to this file will be ignored and overwritten")
lines.append("# Changes to the environment should be made in env_mach_specific.xml")
lines.append("# Run ./case.setup --reset to regenerate this file")
if sh_init_cmd:
lines.append("source {}".format(sh_init_cmd))
if "SOFTENV_ALIASES" in os.environ:
lines.append("source $SOFTENV_ALIASES")
if "SOFTENV_LOAD" in os.environ:
lines.append("source $SOFTENV_LOAD")
if self._unit_testing or self._standalone_configure:
job = None
else:
job = case.get_primary_job()
modules_to_load = self._get_modules_for_case(case, job=job)
envs_to_set = self._get_envs_for_case(case, job=job)
filename = ".env_mach_specific.{}".format(shell)
if modules_to_load is not None:
if module_system == "module":
lines.extend(self._get_module_commands(modules_to_load, shell))
else:
for action, argument in modules_to_load:
lines.append("{} {} {}".format(sh_mod_cmd, action, "" if argument is None else argument))
if envs_to_set is not None:
for env_name, env_value in envs_to_set:
if shell == "sh":
if env_name:
lines.append("export {}={}".format(env_name, env_value))
else:
lines.append("source {}".format(env_value))
elif shell == "csh":
if env_name:
lines.append("setenv {} {}".format(env_name, env_value))
else:
lines.append("echo \"This case includes a shell source file {} which cannot be used from csh type shells\"".format(env_value))
else:
expect(False, "Unknown shell type: '{}'".format(shell))
with open(os.path.join(output_dir, filename), "w") as fd:
fd.write("\n".join(lines))