Earlier quoted context omitted.
Ah interesting, is there any workaround for Mac? Otherwise, I may just have to fallback to stripping the man page formatting and sending it to less.
The actual `man` command does this: /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | /usr/bin/less -is So you could do it "manually" that way. Not the cleanest or prettiest solution but it's much lighter weight than using something like pandoc. EDIT: Full example: { /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | /usr/bin/less -is; }
Help Message for Shell Scripts
101–110 of 129 posts
Re: Help Message for Shell Scripts
#102Re: Help Message for Shell Scripts
#103You duct tape a flashlight to the bulkhead so you can work hands free and actually see what you are doing. All you have on you is a broken pocket knife but it’ll do because all you need to accomplish right now is to tighten the housing screws enough. You know this for a fact because you’ve done it three times already in the last 24 hours.
It’s not even a documented procedure — you’ll replace the housing mounts entirely when you’re back at port in three days’ time. You guarantee it — this is the first thing you’ll do even, when you get back to shore. You have my word on that, captain!
The duct tape came unstuck. It was damp and doesn’t work so well (at all) when it’s wet. The flashlight survived the fall. More tape this time should do the job. Tape mount version 2 will still unstick of course, eventually. Nothing stops the damp at sea, but if you use enough tape then you’ll have fixed the power by the time the tape fails. That’s your plan B and you’re sticking to it.
Sure, you could do this job better if you had an impact driver with an automatically illuminated bit chuck, but buying one of those is further down the todo list than fixing the power on the boat, making it back to port, and ensuring the power doesn’t fail this way again, as promised. Or at least won’t fail for the next few shifts.
On your days off you relax by programming in Bash.
Re: Help Message for Shell Scripts
#104Earlier quoted context omitted.
You can also use add a hyphen ( https://linuxhint.com/bash-heredoc-tutorial/
Seriously, bash has too many obscure features.
a five year old took his first aware car ride, and at a gas station saw the trunk of the car next to theirs open. he said "seriously, bmw has too many obscure features." after all, a car for him was where you put the baby seat. and why would you put that in a compartment with no windows or air, that's too small to even fit a baby seat.
did you enjoy the ride?
Re: Help Message for Shell Scripts
#105Re: Help Message for Shell Scripts
#106Even better: Don’t use bash. I started using Python instead of bash. It’s way better to read and more maintainable. If I need the performance of native-Unix commands, I can still use them using subprocess.
Re: Help Message for Shell Scripts
#107Earlier quoted context omitted.
Seriously, bash has too many obscure features.
Ruby and Perl have `here` docs as well. And Ruby 2.5 has an enhancement which preserves leading whitespace.
Re: Help Message for Shell Scripts
#108You can also use a "here document" help() { cat Options: Input file to read. Output file to write. Use '-' for stdout. -h Show this message. EOH } If the indentation bugs you, you can use a simpler sed trick to remove leading space so that you can indent it as desired: help() { sed -e 's/ //' Options: Input file to read. Output file to write. Use '-' for stdout. -h Show this message. EOH }
Or just a multiline string: #!/bin/bash USAGE="my-script — does one thing well Usage: my-script Options: Input file to read. Output file to write. Use '-' for stdout. -h Show this message. " help() { echo "$USAGE" } This is my standard approach which is cleaner for putting the documentation at the very top of the file like the linked article.
Do you know if these are portable?
Re: Help Message for Shell Scripts
#109Didn't work on macOS (multiple sed errors - switches differ from Linux) but prompted me to write a help function ;-)
I have a project that makes heavy use of sed.. On macOS, I `brew install gnu-sed` and use `gsed` instead, so it works like other platforms.
Re: Help Message for Shell Scripts
#110You can also use a "here document" help() { cat Options: Input file to read. Output file to write. Use '-' for stdout. -h Show this message. EOH } If the indentation bugs you, you can use a simpler sed trick to remove leading space so that you can indent it as desired: help() { sed -e 's/ //' Options: Input file to read. Output file to write. Use '-' for stdout. -h Show this message. EOH }
Or just a multiline string: #!/bin/bash USAGE="my-script — does one thing well Usage: my-script Options: Input file to read. Output file to write. Use '-' for stdout. -h Show this message. " help() { echo "$USAGE" } This is my standard approach which is cleaner for putting the documentation at the very top of the file like the linked article.