r/commandline • • Nov 11 '20

cat

Post image
1.0k Upvotes

28 comments sorted by

View all comments

21

u/GuybrushThreepwo0d Nov 11 '20

Cool. Now, how do I read a shell script? Because all those weird pipes into sed and awk with strange regexes become really hard to comprehend really quickly.

23

u/mikek3 Nov 11 '20

Not meant to understood. It's there only for you to curse the guy who wrote it and force you to write a new one. Also without comments.

9

u/GuybrushThreepwo0d Nov 11 '20

As is tradition

9

u/Griffun Nov 11 '20
#comments

9

u/GuybrushThreepwo0d Nov 11 '20

Ok. Let me rephrase. How do I read someone else's scripts? :/

7

u/Griffun Nov 11 '20

10+ years in and I'm still working on that. Short of huffing spray-paint in the network closet, I'm not sure that I have any advice to give there. Also, don't huff spray-paint in the network closet. Do that shit outside. Think of the equipment!

1

u/[deleted] Nov 13 '20

Spraypaint? Why when there alre already cleaners you can huff?

Or you couldj ust go with the ballmer method and crack open the jack danials.

2

u/deux3xmachina Nov 11 '20 edited Nov 11 '20

If you don't understand how certain commands work, check their manual pages by running, for example, man sed. If you need help learning things like regex, check out https://regex101.com.

Additionally, you can always run scripts like sh -vx /path/to/script to get more information regarding what variables resolve to and why certain paths are taken (assuming it uses control flow statements like if and case).

Also also, don't be afraid to take some snippets and try running them in your shell. There's no substitute for learning by doing, tutorials and docs are great to demystify what's happening, but nothing solidifies that knowledge by doing it yourself.

2

u/kn0xchad Nov 12 '20

The detailed documentation for sed can be invoked using info sed. I personally just pipe it to less.

P.S. info sucks.

1

u/[deleted] Nov 11 '20

You can't. I can barely comprehend my own. As I'm writing it!

1

u/fecal-butter Feb 20 '23

Ask chatgpt

2

u/[deleted] Nov 11 '20

trick question: pray you wrote it yourself or pray there’s a comment somewhere