Calling custom function in bash results in "Command not found"

pjominet

I'm trying this to display a default helptext when no parameters are given when executing the script:

if [[ $@ ]]; then 
    do stuff
else displayHelp; 
fi

displayHelp() {
    echo "some helptext"
}

But for some reason, when executing the script on console, it says:

./myScript.sh: Line 48: displayHelp: Command not found

The same occurs when I call this function via -h parameter

muton

Functions must be defined before they can be used. So put the method before your call it:

displayHelp() {
    echo "some helptext"
}

if [[ $@ ]]; then 
    do stuff
else displayHelp; 
fi

or put your main code in another method and call this one at the end of your script:

main() {
    if [[ $@ ]]; then 
        do stuff
    else displayHelp; 
    fi
}

displayHelp() {
    echo "some helptext"
}

main "$@"

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

-bash: cfssl: command not found

分類Dev

Bash alias: command not found

分類Dev

-bash: tsc: command not found

分類Dev

Git bash Command not found

分類Dev

$'\r' - command not found in bash

分類Dev

wget command not found in git bash

分類Dev

Bash script - unix - command not found

分類Dev

Heroku + gunicorn not working (bash: gunicorn: command not found )

分類Dev

pod install -bash: pod: command not found

分類Dev

firebase-tools "-bash:firebase:command not found"

分類Dev

bash_completion causing a 'command not found' in terminal

分類Dev

heroku error bash: gunicorn: command not found

分類Dev

bash command not found when setting a variable

分類Dev

-bash: 400:: command not found when open terminal

分類Dev

command not found assigning value to array in bash

分類Dev

calling function multiple times with new results

分類Dev

Bash: Help honing a custom function

分類Dev

"-bash: gcc: command not found" using cygwin when compiling c?

分類Dev

How to solve the defining variables in bash prompt command not found the problem

分類Dev

pkg install -forge general bash: pkg: command not found

分類Dev

"command not found" when using arithmetic expansion in bash shell

分類Dev

Capturing results of dialog call embedded in a bash function

分類Dev

Calling Azure Function 150 times by HTTP results in exception

分類Dev

How to enable suggestion if command not found ("did you mean..." feature) in "bash" shell?

分類Dev

Calling function object returned doesn't show same results? Python3.x

分類Dev

.bash_profileのパスでエラーが発生します: "-bash:flutter:command not found"

分類Dev

Bashスクリプトが "Command Not Found"を空の行に出力する

分類Dev

psql: command not found Mac

分類Dev

JSON Server: Command Not Found

Related 関連記事

  1. 1

    -bash: cfssl: command not found

  2. 2

    Bash alias: command not found

  3. 3

    -bash: tsc: command not found

  4. 4

    Git bash Command not found

  5. 5

    $'\r' - command not found in bash

  6. 6

    wget command not found in git bash

  7. 7

    Bash script - unix - command not found

  8. 8

    Heroku + gunicorn not working (bash: gunicorn: command not found )

  9. 9

    pod install -bash: pod: command not found

  10. 10

    firebase-tools "-bash:firebase:command not found"

  11. 11

    bash_completion causing a 'command not found' in terminal

  12. 12

    heroku error bash: gunicorn: command not found

  13. 13

    bash command not found when setting a variable

  14. 14

    -bash: 400:: command not found when open terminal

  15. 15

    command not found assigning value to array in bash

  16. 16

    calling function multiple times with new results

  17. 17

    Bash: Help honing a custom function

  18. 18

    "-bash: gcc: command not found" using cygwin when compiling c?

  19. 19

    How to solve the defining variables in bash prompt command not found the problem

  20. 20

    pkg install -forge general bash: pkg: command not found

  21. 21

    "command not found" when using arithmetic expansion in bash shell

  22. 22

    Capturing results of dialog call embedded in a bash function

  23. 23

    Calling Azure Function 150 times by HTTP results in exception

  24. 24

    How to enable suggestion if command not found ("did you mean..." feature) in "bash" shell?

  25. 25

    Calling function object returned doesn't show same results? Python3.x

  26. 26

    .bash_profileのパスでエラーが発生します: "-bash:flutter:command not found"

  27. 27

    Bashスクリプトが "Command Not Found"を空の行に出力する

  28. 28

    psql: command not found Mac

  29. 29

    JSON Server: Command Not Found

ホットタグ

アーカイブ