简体   繁体   English

在bash脚本中执行tcsh命令

[英]execute tcsh command in bash script

In a bash script I need to execute this tcsh command. 在bash脚本中,我需要执行此tcsh命令。 This command works fine in a tcsh command prompt but not in my bash script. 该命令在tcsh命令提示符下工作正常,但在我的bash脚本中却无法正常工作。

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

I have tried several things like adding 我已经尝试了几种方法,例如添加

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

but then it says: No such file or directory. 但随后却说:没有这样的文件或目录。

Edit: current code: 编辑:当前代码:

# 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

EDIT again: 再次编辑:

Environmental variables are actually set, but not for the user who runs the script 实际上设置了环境变量,但没有为运行脚本的用户设置

  • /app/modules/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/gcc/openmpi/lib64';setenv LD_RUN_PATH '/app/mpfr/2.4.0/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:/app/xemacs/21.5.29/LMWP3/share/man:/app/j2re/1.6.0_22/LMWP3/man:/usr/lib64/mpi/gcc/openmpi/man:/usr/share/man:/opt/quest/man:/usr/local/man:/usr/man:/opt/lsb/man:/opt/mpich/man:/opt/gnome/share/man:/app/modules/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/LMWP3/bin:/app/vim/7.3.021/LMWP3/bin:/app/xemacs/21.5.29/LMWP3/bin:/app/thunderbird/3.1.6/LMWP3:/app/thunderbird/3.1.6/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/bin:/app/ica/client/11.1:/ap / app / modules / 0 / bin / modulecmd tcsh加载gcc / 4.3.4 setenv LD_LIBRARY_PATH'/app/mpfr/2.4.0/lib:/app/gmp/4.2.4/lib:/usr/lib64/mp​​i/gcc / openmpi / lib64'; setenv LD_RUN_PATH'/app/mpfr/2.4.0/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:/app/xemacs /21.5.29/LMWP3/share/man:/app/j2re/1.6.0_22/LMWP3/man:/usr/lib64/mp​​i/gcc/openmpi/man:/usr/share/man:/opt/quest/man :/ usr / local / man:/ usr / man:/ opt / lsb / man:/ opt / mpich / man:/ opt / gnome / share / man:/ app / modules / 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/LMWP3/bin:/app/vim/7.3.021/LMWP3/bin:/app/xemacs/21.5.29/LMWP3/bin:/app/thunderbird/3.1.6/LMWP3: /app/thunderbird/3.1.6/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 / bin:/app/ica/client/11.1:/ ap p/acroread/9.4.0/LMWP3/Adobe/Reader9/bin:/home/ebrfred/.afs/0/rbin:/home/ebrfred/.afs/0/pbin:/env/seln/bin:/home/ebrfred/.afs/0/ibin:/usr/atria/bin:/usr/afsws/bin:/usr/NX/bin:/usr/lib64/mpi/gcc/openmpi/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/quest/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/openwin/bin:/opt/cross/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/gnome/bin:/usr/lib/qt3/bin:/usr/dt/bin:/usr/ccs/bin:/app/arc/0/bin';setenv LMFILES '/env/common/modules/firefox/3.6.12:/env/common/modules/acroread/9.4.0:/env/common/modules/flashplayer/10.1:/env/common/modules/ica/11.1:/env/common/modules/j2re/1.6.0_22:/env/common/modules/openoffice/3.2.1:/env/common/modules/thunderbird/3.1.6:/env/common/modules/xemacs/21.5.29:/env/common/modules/vim/7.3.021:/env/common/modules/nxclient/3.4.0.7:/env/common/modules/sametime/8.0.2:/env/common/modules/emacs/23.2:/home/ebrfred/.afs/0/imodules/isit_modules:/env/common/modules/gmp/4.2.4:/env/common/modules/mpfr/2.4.0:/env/c p / acroread / 9.4.0 / LMWP3 / Adob​​e / Reader9 / bin:/home/ebrfred/.afs/0/rbin:/home/ebrfred/.afs/0/pbin:/ env / seln / bin:/ home / ebrfred / .afs / 0 / ibin:/ usr / atria / bin:/ usr / afsws / bin:/ usr / NX / bin:/ usr / lib64 / mpi / gcc / openmpi / bin:/ usr / bin:/ bin :/ usr / sbin:/ sbin:/ opt / quest / bin:/ usr / local / bin:/ usr / bin / X11:/ usr / X11R6 / bin:/ usr / games:/ opt / kde3 / bin:/ usr / openwin / bin:/ opt / cross / bin:/ usr / lib / mit / bin:/ usr / lib / mit / sbin:/ opt / gnome / bin:/ usr / lib / qt3 / bin:/ usr / dt / bin:/ usr / ccs / bin:/ app / arc / 0 / bin'; setenv LMFILES '/ env / common / modules / firefox /3.6.12:/env/common/modules/acroread/9.4.0: /env/common/modules/flashplayer/10.1:/env/common/modules/ica/11.1:/env/common/modules/j2re/1.6.0_22:/env/common/modules/openoffice/3.2.1:/env /common/modules/thunderbird/3.1.6:/env/common/modules/xemacs/21.5.29:/env/common/modules/vim/7.3.021:/env/common/modules/nxclient/3.4.0.7: /env/common/modules/sametime/8.0.2:/env/common/modules/emacs/23.2:/home/ebrfred/.afs/0/imodules/isit_modules:/env/common/modules/gmp/4.2.4 :/env/common/modules/mpfr/2.4.0:/ env / c ommon/modules/gcc/4.3.4';setenv LOADEDMODULES 'firefox/3.6.12:acroread/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:sametime/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/4.3.4/lib/pkgconfig:/opt/gnome/lib64/pkgconfig:/opt/gnome/share/pkgconfig';+ exit 0 ommon / modules / gcc / 4.3.4'; setenv LOADEDMODULES'firefox / 3.6.12:acroread / 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:sametime / 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/4.3.4/lib/pkgconfig:/opt/gnome/lib64/pkgconfig:/opt/gnome/share/pkgconfig'; +退出0

See man tcsh . 参见man tcsh You must quote the eval ... command: 您必须引用eval ...命令:

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

Otherwise bash will interpret the backticks command. 否则bash将解释backticks命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM