在BASH脚本中执行TCSH命令



在bash脚本中,我需要执行此tcsh命令。此命令在TCSH命令提示符中正常工作,但在我的bash脚本中不行。

eval `/app/modules/0/bin/modulecmd tcsh $variable`

我尝试了几件事,例如添加

/usr/bin/tcsh -c eval `/app/modules/0/bin/modulecmd tcsh $variable`

但随后说:没有这样的文件或目录。

编辑:当前代码:

# hook for some commands
echo 'To be sure the version that are loading exist for your platform plase use: "module aplikation load/version" instead of "module load application". A check will then be done.'
cmd=$(basename "$0") # it givs error here if i start with: tcsh -v xmodule load firefox/3.6.13     
var1=$(echo "$@" | awk '{print $2}' | cut -f1 -d"/") # Gets the application name and put it into var1
var2=$(echo "$@" | grep -o '[^/]*$')  # Gets version name and put it into var2 
if [[ $cmd = "xmodule" ]]
        then
#First if statement: checking if a spesific version of an apllication is requested.
        if  [[ ${@} =~ .*/.* && ${@} =~ ((^)|([ ]))load(($)|([ ])) ]]
        then
           if find /app/$var1 -noleaf -maxdepth 1 -type l -o -type d | grep $var2; then #matching version to symlink or dir in /app/appname/
           echo "$@"
           tcsh -c 'eval `/app/modules/0/bin/modulecmd tcsh $@`'  #execute the module command as normal if version exist
           exit $?
        else
           echo "Could not find $var1 or $var2, one of these things happend:"
           echo "$var1 was misspelled"
           echo "$var2 was misspelled"
           echo "version does exist as a module but not for your platform (see module avail $var1). Printing a list of suported versions:"
                ls /app/$var1/
           echo "exiting: please rety again"
           exit $?
        fi
fi
# Next check. Checking if default module version is loaded
fi
exit

再次编辑:

实际上是设置了环境变量,但对于运行脚本的用户而不是设置了

的用户
  • /app/模块/0/bin/modulecmd tcsh load gcc/4.3.4 setEnv ld_library_path'/app/mpfr/2.4.0/lib:/app/gmp/4.2.4/lib:/usr/lib64/mpi/mpi/gcc/gcc/openmpi/lib64'; setenv ld_run_path/lib:/app/gmp/4.2.4/lib:/app/gcc/4.3.4/lib64:/app/gcc/4.3.4/lib'.setenv manpath'/app/gcc/4.3.4/man:/app/emacs/23.2/lmwp3/share/man:/app/vim/7.3.021/lmwp3/share/man:/papp/xemacs/21.5.29/lmwp3/share/share/man:/app/man:/app/.0_22/lmwp3/man:/usr/lib64/mpi/gcc/openmpi/man:/usr/share/share/man:/opt/quest/man:/usr/usr/local/man:/usr/usr/man:/opt/lsb/man:/opt/mpich/man:/opt/gnome/share/share/man:/app/模块/0/man:/app/modules/0/man'; setenv path'/app/gcc/4.3.4/bin:/app/firefox/3.6.12/lmwp3:/app/emacs/23.2/lmwp3/bin:/app/sametime/8.0.2:/app/nxclient/3.4.0.7/lmwphp3/bin:/app/app/vim/7.3.021/lmwp3/bin:/app/xemacs/21.5.29/lmwp3/bin:/app/thunderbird/3.1.6/lmwp3:/lmwp3:/app/thunderbird/3.1.6/lmwp3/lmwp3/bin:/app/openoffice/3.2.1/lmwp3/opt/openoffice.org3/program:/app/openoffice/3.2.1/lmwp3/openoffice.org3/program:/app/j2re/1.6.0_22/lmwp3/lmwp3/bin:/app/app/app/app/ica/客户端/11.1:/app/acroread/9.4.0/lmwp3/adobe/reader9/bin:/home/ebrfred/.afs/0/rbin:/home/ebrfred/.afs/0/0/0/pbin:/envy/envy/envy/seln/seln/bin:/home/ebrfred/.afs/0/ibin:/usr/asr/atria/bin:/usr/afsws/bin:/usr/nx/bin:/usr/usr/lib64/lib64/mpi/gcc/openmpi/bin:/usr:/usr:/usr:/usr/bin:/bin:/usr/sbin:/sbin:/opt/quest/bin:/usr/locar/bin:/usr/bin/x11:/usr/x11r6/bin/bin:/usr/usr/opt/opt/opt/opt/opt/kde3/bin:/usr/openwin/bin:/opt/opt/cross/bin:/usr/lib/mit/bin:/usr/lib/lib/sbin:/opt/opt/gnome/bin/bin:/usr/lib/qt3/qt3/qt3/qt3/qt3/qt3/qt3/qt3/bin:/usr/dt/bin:/usr/ccs/bin:/app/arc/0/bin'; setenv lmfiles '/em>'/em>'/env/common/modules/firefox/3.6.6.12://env/common/common/acroread/9.4.0:/env/common/modules/flashplayer/10.1:/ENV/COMMON/MODULES/MMODULES/11.1:/ENV/COMMON/COMMON/MODULES/MMODULES/J2RES/J2RE/1.6.6.0_22:/envy/END/END/END/END/END/END/common/openoffice/3.2.1:/env/common/modules/thunderbird/3.1.6:/ENV/COMMON/MODULES/XEMACS/21.5.29:/eenv/common/modules/mmodules/modules/7.3.021://7.3.021:/env/common/common/nxclient/3.4.0.7:/env/common/modules/sametime/8.0.2:/eenv/common/modules/modules/emacs/23.2:/home/ebred/ebred/ebred/ebred/.afs/.afs/0/imodules/imodules/isit_modules::/ENV/COMMON/MODULES/GMP/4.2.4:/env/common/modules/mpfr/2.4.0:/env/env/common/modules/gcc/4.3.4'; setenv loadedmodules/9.4.0:flashplayer/10.1:ICA/11.1:J2RE/1.6.0_22:openoffice/3.2.1:thunderbird/3.1.6:xemacs/21.5.29:vim/7.3.021:nxclient/3.4.0.7:samameTime/8.0.2:emacs/23.2:isit_modules:gmp/4.2.4:mpfr/2.4.0:gcc/4.3.4'; setenv pkg_config_path'/app/gcc/gcc/gcc/4.3.4/lib/pkgggconfig:/pkgconfig:/opt/gngn/gngn/gngn/gngn/gngnemome/lib64/pkgconfig:/opt/opt/gnome/share/pkgconfig'; 退出0

请参阅MAN TCSH。您必须引用eval ...命令:

tcsh -c "eval `/app/modules/0/bin/modulecmd tcsh $variable`"

否则bash将解释Backticks命令。

相关内容

  • 没有找到相关文章

最新更新