Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何防止终端回显我的getopts参数?_Bash_Command Line Arguments_Getopts - Fatal编程技术网

Bash 如何防止终端回显我的getopts参数?

Bash 如何防止终端回显我的getopts参数?,bash,command-line-arguments,getopts,Bash,Command Line Arguments,Getopts,我正在编写一个脚本,其中包括getopts,它运行良好: #!/bin/bash # Define help function for options function help(){ echo echo -e $YELLOW'--->COMMAND LINE OPTIONS:'$ENDCOLOR echo echo "Usage example:"; echo "script_name [(-i|--install) string] [(-u|-

我正在编写一个脚本,其中包括
getopts
,它运行良好:

#!/bin/bash

# Define help function for options
function help(){
    echo
    echo -e $YELLOW'--->COMMAND LINE OPTIONS:'$ENDCOLOR
    echo
    echo "Usage example:";
    echo "script_name [(-i|--install) string] [(-u|--uninstall) string] [(-b|--backup) string] [(-r|--restore) string] [(-m|--manualupdate) string] [(-p|--passwordreset) string] [(-a|--accessdetails) string] [(-t|--updatetoolkit)] [(-U|--updateall)]";
    echo "Options:";
    echo
    echo "-i or --install string: Install an app.";
    echo "-u or --uninstall string: Uninstall an app.";
    echo "-b or --backup string: Backup an the config file for an app.";
    echo "-r or --restore string: Restore an app config file from backup.";
    echo "-m or --manualupdate string: Manually update a specific app.";
    echo "-p or --passwordreset string: Reset the password to an app.";
    echo "-a or --accessdetails string: View the access details for an app.";
    echo "-t or --updatetoolkit: Update the toolkit.";
    echo "-U or --updateall: Update Linux and all apps.";
    exit 1;
}

# Reset option vars
updatetoolkit=0;
updateall=0;

# Capture options to getopts
export ARGS=$(getopt -o "i:u:b:r:m:p:a:tUh" -l "install:,uninstall:,backup:,restore:,manualupdate:,passwordreset:,accessdetails:,updatetoolkit,updateall,help" -n "script_name" -- "$@");

if [ $? -ne 0 ];
then
    help;
fi

eval set -- "$ARGS";

while true; do
    case "$1" in
        -i|--install)
            shift;
                    if [ -n "$1" ]; 
                    then
                        install="$1";
                        source $SCRIPTSOURCE/$1/$1-installer.sh
                        shift;
                    fi
            ;;
        -u|--uninstall)
            shift;
                    if [ -n "$1" ]; 
                    then
                        uninstall="$1";
                        source $SCRIPTSOURCE/$1/$1-uninstaller.sh
                        shift;
                    fi
            ;;
        -b|--backup)
            shift;
                    if [ -n "$1" ]; 
                    then
                        backup="$1";
                        source $SCRIPTSOURCE/$1/$1-constants.sh
                        source $SCRIPTPATH/inc/app-backup-controller.sh
                        shift;
                    fi
            ;;
        -r|--restore)
            shift;
                    if [ -n "$1" ]; 
                    then
                        restore="$1";
                        source $SCRIPTSOURCE/$1/$1-constants.sh
                        source $SCRIPTPATH/inc/app-restore-controller.sh
                        shift;
                    fi
            ;;
        -m|--manualupdate)
            shift;
                    if [ -n "$1" ]; 
                    then
                        manualupdate="$1";
                        source $SCRIPTSOURCE/$1/$1-updater.sh
                        shift;
                    fi
            ;;
        -p|--passwordreset)
            shift;
                    if [ -n "$1" ]; 
                    then
                        passwordreset="$1";
                        source $SCRIPTSOURCE/$1/$1-constants.sh
                        source $SCRIPTPATH/inc/app-password-reset.sh
                        shift;
                    fi
            ;;
        -a|--accessdetails)
            shift;
                    if [ -n "$1" ]; 
                    then
                        accessdetails="$1";
                        source $SCRIPTSOURCE/$1/$1-constants.sh
                        source $SCRIPTPATH/inc/app-access-details.sh
                        shift;
                    fi
            ;;
        -t|--updatetoolkit)
            shift;
                    updatetoolkit="1";
                    source $SCRIPTPATH/maintenance/update.sh
            ;;
        -U|--updateall)
            shift;
                    updateall="1";
                    source $SCRIPTPATH/maintenance/distro-update.sh
            ;;

        --)
            shift;
            break;
            ;;
    esac
done

# Check required arguments
但是,每当我使用参数运行脚本时,它都会执行它应该执行的操作,但它会在终端中打印参数,即:

-p

Remaining code...

如何防止这种情况发生?

bash-x/your/script
并查看
-p
的打印位置。@whjm哇。我知道bash,但我忘了有调试标志。原来我有一个
echo$1
,我没有注释掉。谢谢如果您快速解释一下
bash-x
在这种情况下是如何有用的,我会将其标记为正确的。