本文介绍了如何解决“转移:不能转移那么多"?运行shell脚本时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用不同方法的shell脚本.该脚本是

I have a shell script with different methods.The script is

    status(){
    PID=$(ps -ef | grep jmeter_script.sh|grep -v grep|awk '{print $2}')
    }

    start(){
    shift
    if [ "$#" -ne 2 ]; then
            exit 1;
    fi
    jmeter.sh -n -t "$1"  -l "$2"
    }

    stop(){
        while true; do
            read -p "Do you really want to stop?" yn
            case $yn in
                [Yy]* ) ps -ef | grep jmeter | grep -v grep | awk '{print $2}'|xargs kill; break;;
                [Nn]* ) exit;;
                * ) echo "Please answer yes or no.";;
            esac
view(){
#some code
}

    ####Main
    while [ "$1" != "" ]; do
    case "$1" in
            start )
                start
                ;;

            stop)
                stop
                ;;

            status)
                status
                ;;
            view)
                view
                ;;
            *)
                echo $"Usage: $0 {start|stop|status|view}"
                exit 1
            esac
        shift
    done

当我尝试使用./jmeter_script.sh start abc.jmx log.jtl运行脚本时,出现错误消息./jmeter_script.sh: 19: shift: can't shift that many,然后退出.我在ubuntu服务器上运行我的脚本.我已尝试解决此问题,但找不到该错误的任何正确链接.有人帮忙.

When I try to run the script using ./jmeter_script.sh start abc.jmx log.jtl I get an error saying ./jmeter_script.sh: 19: shift: can't shift that many and then exit. I am running my script on ubuntu server. I have tried to resolve this but I ddin't find any proper link for this error. Someone please help.

推荐答案

这些是函数,而不是方法.不要在没有开始应用OOD术语的情况下投入过多.

Those are functions, not methods. Don't go overboard applying OOD terminology where it doesn't begin to apply.

避免移位错误的最佳方法是在用完参数时不要移位.检查您转移的$#之前的值.

The best way to avoid shift errors is not to shift when you have run out of arguments. Check the value of $# BEFORE you shift.

如果不指定很多标志,则解析ps -ef输出会更容易.您只需要PID和PNAME.

It would be easier to parse your ps -ef output if you don't specify lots of flags. All you need is PID and PNAME.

这篇关于如何解决“转移:不能转移那么多"?运行shell脚本时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 16:26