• Uncategorized

About linux : How-to-create-flags-for-a-bash-script-duplicate

Question Detail

I am learning bash my self 🙂 and I am stuck on my problem please help!

I have seen many bash scripts which have flags which can be executed without running the whole script like if using proot-distro then we type proot-distro login distroname or proot-distro --help etc.

How can I achieve this?

Question Answer

You basically need to to iterate through the arguments using a while [[ $# -gt 0 ]]; do case $1 in ... esac; shift; done loop. You enable flags, collect optargs, or target files as you go. There are plenty of tutorials and examples on how to do it out there. You can also look at mine as examples. Just avoid relying on getopt[s]. The capability to specify short options together isn’t worth the complexity.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.