16
submitted 1 year ago by j4k3@lemmy.world to c/linux@lemmy.ml

I have been working on my scripts for user/group permissions today. This idea has been on my back burner for awhile. I'm sure others have done this before. I just haven't encountered them yet.

I was thinking of just trying to find the flags where they start a line and put everything in a string array until the next line that starts with a flag. Then I would just call the script with the command, a loop would match the flags and print the matches.

all 6 comments
sorted by: hot top controversial new old
[-] BuoyantCitrus@lemmy.ca 15 points 1 year ago
[-] learnbyexample@programming.dev 3 points 1 year ago

Inspired by explainshell, I wrote a script (https://github.com/learnbyexample/command_help) to be used from the terminal itself. It is a bit buggy, but works well most of the time. For example:

$ ch grep -Ao
       grep - print lines that match patterns

       -A NUM, --after-context=NUM
              Print NUM lines of trailing context after matching lines.  Places a
              line containing a group separator (--) between contiguous groups of
              matches.  With the -o or --only-matching option, this has no effect
              and a warning is given.

       -o, --only-matching
              Print  only  the matched (non-empty) parts of a matching line, with
              each such part on a separate output line.
[-] inspxtr@lemmy.world 2 points 1 year ago

omg that is lovely. Kinda like https://regex101.com/ for regular expressions.

[-] bitwolf@lemmy.one 4 points 1 year ago

I like to use cht.sh you it maps it's subdirectories to commands and you just curl it.

Eg:

curl cht.sh/cat curl cht.sh/grep

[-] phoenix591@lemmy.phoenix591.com 2 points 1 year ago

you're probably looking for getopt/getopts. one big difference between them is getopt handles --long options while getopt doesn't.

other example

this post was submitted on 07 Aug 2023
16 points (100.0% liked)

Linux

48073 readers
605 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS