Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
Linux 如何使用';阅读-p';在'之后;评估';在ZSH?_Linux_Shell_Scripting_Zsh - Fatal编程技术网

Linux 如何使用';阅读-p';在'之后;评估';在ZSH?

Linux 如何使用';阅读-p';在'之后;评估';在ZSH?,linux,shell,scripting,zsh,Linux,Shell,Scripting,Zsh,我想编写一个ZSH函数,建议我在错误的git push之后使用yadm push。 我已经设置了别名git=“correct git”和以下功能: function correct (){ if [ "$1" = "git" ] && [ "$2" = "push" ]; then eval "command $1 $2" || echo "Try yadm?" select yn in "Yes" "No"; do

我想编写一个ZSH函数,建议我在错误的
git push
之后使用
yadm push
。 我已经设置了
别名git=“correct git”
和以下功能:

function correct (){
    if [ "$1" = "git" ] && [ "$2" = "push" ]; then
        eval "command $1 $2" ||
        echo "Try yadm?"
        select yn in "Yes" "No"; do
            case $yn in
                Yes ) yadm $2; break;;
                No ) break;;
            esac
        done
    fi
}
上面的工作与预期的一样,而我在使用
read-p
时没有做到这一点:

function correct (){
    if [ "$1" = "git" ] && [ "$2" = "push" ]; then
        eval "command $1 $2" || 
        while true; do
            read -p "Try yadm? (y/n)" yn
            case $yn in
                [Yy]* ) yadm $2; break;;
                [Nn]* ) break;;
                * ) echo "Please answer yes or no.";;
            esac
        done
    fi
}

eval
语句之后,如何使用
read-p
。在ZSH中,
read-p
希望从协进程中读取,而不是指示提示符。回答

两个版本中的第二行应该是
命令$1$2 | |
,以避免使用
eval
,即使它在if语句中应该是正常的


咨询
man zshbuiltins
会有帮助。

好的,这与eval的使用毫无关系。在ZSH中,
read-p
希望从协进程中读取,而不是指示提示符。回答

两个版本中的第二行应该是
命令$1$2 | |
,以避免使用
eval
,即使它在if语句中应该是正常的

咨询
man zshbuiltins
会有所帮助

function correct (){
    if [ "$1" = "git" ] && [ "$2" = "push" ]; then
        command $1 $2 ||
        while true; do
            printf "Try yadm? (y/n)"
            read yn
            case $yn in
                [Yy]* ) yadm $2; break;;
                [Nn]* ) break;;
                * ) echo "Please answer yes or no.";;
            esac
        done
    fi
}