'How to make --version custom command in linux

So, I just started to introduce myself with custom commands in Linux and created one but now I want it to be executed globally like this, say my command is owncmd #!/bin/bash echo "Heya custom commands"

this works perfectly fine when I execute $-owncmd but I wanted to write the version or help page like : $- owncmd --version OR owncmd --help



Solution 1:[1]

You could check the input $1 to see whether it is -v or --version in which case you print the version and stop without executing the actual code. Idem for -h or --help.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1