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
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]
コメントを追加