How do you call a function defined in .bashrc from the shell?

后端 未结 6 1466
醉梦人生
醉梦人生 2021-01-30 19:30

In my .bashrc, I have a function called hello:

function hello() {
   echo \"Hello, $1!\"
}

I want to be able to invoke hello() from the shell a

6条回答
  •  滥情空心
    2021-01-30 20:11

    The test in your function won't work - you should not have brackets around the -z clauses, and there should be a space between if and the open bracket. It should read:

    function coolness() {
    
        if [ -z "$1" -o -z "$2" ]; then
            echo "Usage: $0 [sub_package] [endpoint]";
            exit 1;
        fi
        echo "Hi!"
    }
    

提交回复
热议问题