Live data from Hacker News

Use long flags when scripting (2013)

changelog.com

161–170 of 197 posts

Re: Use long flags when scripting (2013)

#161

I wonder a bit, that those POSIX comments are so far in the bottom of this discussion. I mean, you are loosing portability by using long flags (because it is not standard compliant) and yet it seems to be just a footnote in this discussion...

Not a lot of people these days care about portability, unfortunately. You'll be lucky if your project's build scripts run the same way on both Debian and vanilla macOS. And when they don't, the answer people will give you is probably something like “Just install GNU tools!”. *BSD? Forget about it.

Re: Use long flags when scripting (2013)

#162

Great suggestion, but I'd go for a middle ground: use long flags for the long tail, but short flags are fine for stuff that's very commonly used. I think I'll continue to write these: grep -i rm -rf ln -s gzip -v sed -e instead of: grep --ignore-case rm --recursive --force ln --symbolic gzip --verbose sed --expression If you're working on shell scripts, you probably know certain short flags well enough that long flag…

> If you're working on shell scripts, you probably know certain short flags well enough that long flags just add clutter and don't improve readability. What about other people who might read the script?

I have more difficulties to read long flags. The people who want to improve by reading my scripts will have to search for the short flags because nobody use long flags from command line. IMHO the benefits of long flags vs short ones are not obvious.

Re: Use long flags when scripting (2013)

#163
post #159

Earlier quoted context omitted.

I think the dot actually gives you issues on Mac? Or something like that. I remember encountering issues with it.

You have to specify a directory for the find on Mac; it's only a GNUism to omit it.

Oh I see, I got it backwards somehow. Thanks!

Re: Use long flags when scripting (2013)

#164
post #133

Earlier quoted context omitted.

I think you're assuming a level of Unix knowledge that less and less new people in the field are going to have.

Someone who's tasked with maintaining shell scripts better be familiar with the shell.

that's kinda his point.

Kids today no longer know the shell. They think just writing some yaml files in ansible is sufficient. Giving them a shell script won't help at all.

Re: Use long flags when scripting (2013)

#165

Earlier quoted context omitted.

Related to this, they're less likely to do something unexpected. Many programs use -v as a short flag for --version , but some (such as curl) use it as short for --verbose Probably something you'd catch pretty quickly, but still.

Wow, that's funny, I normally expect '-v' to be verbose, but maybe I just use a lot of `tar` and `curl`!

Or maybe cp, or rm, or rsync, or mount, or wget, or netcat (both gnu and bsd) ... it’s really pretty reasonable to expect -v to mean verbose ;-).

Re: Use long flags when scripting (2013)

#166

Great suggestion, but I'd go for a middle ground: use long flags for the long tail, but short flags are fine for stuff that's very commonly used. I think I'll continue to write these: grep -i rm -rf ln -s gzip -v sed -e instead of: grep --ignore-case rm --recursive --force ln --symbolic gzip --verbose sed --expression If you're working on shell scripts, you probably know certain short flags well enough that long flag…

Indeed. Almost all arguments are "readability" are only relevant to a given reader. Everything is hard to read until you learn to read it.

Re: Use long flags when scripting (2013)

#167

Great suggestion, but I'd go for a middle ground: use long flags for the long tail, but short flags are fine for stuff that's very commonly used. I think I'll continue to write these: grep -i rm -rf ln -s gzip -v sed -e instead of: grep --ignore-case rm --recursive --force ln --symbolic gzip --verbose sed --expression If you're working on shell scripts, you probably know certain short flags well enough that long flag…

I would agree. Especially when you have something like https://explainshell.com/ to help you understand a command and its flags. It would be nice to have editor/IDE extensions which can do equivalent of explainshell.com's functionality.

Re: Use long flags when scripting (2013)

#169
post #133

Earlier quoted context omitted.

Someone who's tasked with maintaining shell scripts better be familiar with the shell.

that's kinda his point. Kids today no longer know the shell. They think just writing some yaml files in ansible is sufficient. Giving them a shell script won't help at all.

>Kids today no longer know the shell.

Sounds like Kochan and Wood[0] need some love (and royalties).

Or is learning stuff deprecated these days?

[0] https://www.amazon.com/Unix-Shell-Programming-Stephen-Kochan...

Re: Use long flags when scripting (2013)

#170

Enough idiotic Unix crypticism. Time to grow up and be responsible for making the code readable for the next unfortunate person having to mess with *sh scripts. No excuses, no shortcuts, no turning the time sunk learning random letter combinations into entry barriers for newcomers.

The real shortcut here is the next person wanting to google every answer (instead of taking the time to read part of a manpage).
Post reply on HN