-1

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?

Anonymous
  • 11
  • 3
  • You need to accept and parse command line arguments. – kiner_shah Dec 27 '21 at 10:42
  • 2
    Your question is too broad and has been answered here already: [How do I parse command line arguments in Bash?](https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash) – Léa Gris Dec 27 '21 at 10:53

1 Answers1

1

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.

konsolebox
  • 66,700
  • 11
  • 93
  • 101