You should make a CLI (Command Line Interface).
To do this, you should parse the command line arguments, like --help and --version. You can access them with $1, $2, ...
Here is an example on your code :
#!/bin/bash
cli_help() {
# --help: Shows help message
echo "
owncmd - Custom command
Usage:
owncmd [options]
Options:
--help / -h: Show this message and exit.
--version / -V: Show version number and exit.
"
exit
}
cli_version() {
# --version: Show version
echo "owncmd v1.0"
exit
}
# Argument
case $1 in
"--help"|"-h")
cli_help
;;
"--version"|"-V")
cli_version
;;
esac
# Main program
echo "Heya custom commands"
The program look at the first argument $1.
- If it is
--help or -h: Show an help message (function cli_help) and exit
- If it is
--version or -V: Show version number (function cli_version) and exit
ℹ️ Note: We use -V instead of -v because -v means "verbose mode", not "version".
If there is no --help or --version, the program shows Heya custom commands.
bash(since the shebang, the first line, points to the/bin/bashexecutable). This file is then marked as executable with thexpermission. Most shell programs like that are called "scripts".