在这次发言中,我想匹配,如果一个版本($ VAR2)在路径/应用/ $ VAR1(应用程序名)存在
if
find /app/$var1 -maxdepth 1 -type l -o -type d | grep $var2 #results in a nice list where i can manually get a true match.
# if match is found then execute command.
$realcmd "$@"
rc=$?
exit $rc
else
echo "no match, the version you are looking for does not exist"
fi
当前的代码:这包括我所有的代码(不清洗)。 命令我跑:” ./xmodule负荷的Firefox / 3.6.12" 这个版本做出口
#!/bin/bash
# hook for some commands
#echo $@ #value of sting that is entered after "xmodule"
cmd=$(basename "$0")
#echo "called as $cmd"
if [[ $cmd = "xmodule" ]]
then
realcmd='/app/modules/0/bin/modulecmd tcsh'
# verify parameters
fi
# check if $@ contains value "/" to determine if a specific version is requested.
case "$@" in
*/*)
echo "has slash"
var1=$(echo "$@" | grep -Eio '\s\w*') # Gets the aplication name and put it into var1
echo $var1 # is not printed should be "firefox"
var2=$(echo "$@" | grep -o '[^/]*$') # Gets version name and put it into var2
echo $var2
# Checking if version number exist in /app/appname/
if find /app/$var1 -noleaf -maxdepth 1 -type l -o -type d | grep $var2; then
$realcmd "$@"
exit $?
else
echo "no match, the version you are looking for does not exist"
# Should there be an exit here?
fi
;;
*)
echo "doesn't have a slash"
;;
esac
输出:MYCOMPUTER [上午09点55] [用户/桌面/脚本] - > ./xmodule加载有火狐/ 3.6.12“具有斜线
3.6.12不匹配,您正在寻找不存在的版本
那里是一个空白(以上3.6.1)应该是应用程序的名称。 我现在意识到这肯定是我的问题的罪过,它使用我可能只是/应用程序的路径。 但我不认为我的那部分代码改变任何东西。