【问题标题】:Calling function in the bash from the same function从同一函数调用 bash 中的函数
【发布时间】:2020-03-20 14:08:04
【问题描述】:

我在脚本中编写了一个函数,如果在函数内部的 case 语句中条件不匹配,我想调用该函数。我的脚本不是再次调用该函数,而是打印或回显我的函数名称。

#!/bin/bash

function askUser() {

printf " AUS for Australia \n BAN for Bangladesh \n NEP for Nepal \n IND for India \n ENG for England\n "

read -p " Guess one of the best cricket team according to the country code" read


echo $read

        TEAM="ENG"
        case $read in
        "AUS" | "BAN" | "NEP" | "IND") echo "SORRY!! You Guess the wrong team :(\n" askUser
        ;;
        "ENG") echo "England is the best cricket team and recently had won the ICC trophy. "
        ;;
        *) echo "Please select from the above Teams::):)"
        esac
}
askUser

【问题讨论】:

  • 你需要在这个...:(\n"之后添加;,在函数名之前。
  • 感谢您的回复,这对我很有帮助

标签: bash


【解决方案1】:

put '&& askUser',你现在的方式实际上并没有调用函数 你现在拥有它的方式会将 askUser 作为参数传递给 echo,这就是为什么

【讨论】:

    猜你喜欢
    • 2021-07-21
    • 2015-02-19
    • 2020-12-17
    • 2020-04-08
    • 2015-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 2011-03-25
    相关资源
    最近更新 更多