How to validate unsupported Flags in Bash Script on Debian 12
To validate unsupported Flags in Bash Script on Debian 12
Introduction
Validating unsupported flags in a Bash script means checking if users are using the script with the correct flags (those little commands that start with a hyphen, like -a or -b). It's like a security checkpoint for your script, making sure it runs smoothly and doesn't get confused by wrong instructions.
Procedure
Step 1: Check the OS version by using the below command.
root@linuxhelp:~/linuxhelp# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL=https://bugs.debian.org/
Step 2: Create a script for unsupported flags by using the below command.
root@linuxhelp:~/linuxhelp# vim unsupportedflags
Step 3: Make the executable permission by using the below command.
root@linuxhelp:~/linuxhelp# chmod +x unsupportedflags
Step 4: Long list the files to check executable permission to the script file by using the below command.
root@linuxhelp:~/linuxhelp# ls -la
total 16
drwxr-xr-x 2 root root 4096 Dec 25 05:52 .
drwx------ 8 root root 4096 Dec 25 05:52 ..
ss-rwxr-xr-x 1 root root 560 Dec 25 05:52 unsupportedflags
Step 5: Run the script file with - flags by using the below command.
root@linuxhelp:~/linuxhelp# ./unsupportedflags -a
Script executed successfully
Step 6: Again run the script without – flags by using the below command.
root@linuxhelp:~/linuxhelp# ./unsupportedflags a
Unsupported flags are: a
Supported flags are: abc
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to validate unsupported Flags in Bash Script on Debian 12. Your feedback is much welcome.