Live data from Hacker News

Use long flags when scripting (2013)

changelog.com

71–80 of 197 posts

Re: Use long flags when scripting (2013)

#71

Earlier quoted context omitted.

You must have an alias rm='rm -i' lying around. rm doesn't prompt by default (unless you're the owner of the dir, but not its contents). mkdir demodir && touch demodir/{foo,bar} && rm -r demodir

... huh. No, no alias, I just misread the manpage. I could've sworn that -I was the default......

It's a common thing for IT departments or people making enterprise images to put in because they think it makes it safer.

I feel it does more harm than good by normalising rm -f when you want to recursively delete a folder, but with CD deployments these days it's less of a deal.

Re: Use long flags when scripting (2013)

#72
post #51

Earlier quoted context omitted.

It makes my life easier in most ways. This is one of the costs. And, again, this still bites whenever using different linux distros.

I never said that wasn't the case. That doesn't mean anyone else's attitude is the cause of problems caused by your own choices. #!/bin/bash

I think you mean

    #!/usr/bin/env bash

Re: Use long flags when scripting (2013)

#73
post #67

When writing scripts (CI especially) you'll rarely use, please always use long-flags. It'll save so much headache for the next dev who isn't as up to date with the latest short-hand for az-cli or whatever. When live scripting, feel free to use short.

I think you are right, for all "exotic" tools, long flags are much better and future proof. For regular tools, short flags are so common that they are probably ok.

Your regular tool is not my regular tool. Hell, maybe my regular tool today is not going to be all that regular in 3 years.

Re: Use long flags when scripting (2013)

#74

This is how I write PowerShell scripts. I use full cmdlet names, full argument switch names, and I even specify argument switches to positional arguments. I also do my best to honor common flags like `-WhatIf`, `-Verbose`, and `-ErrorAction`. So I end up with scripts like this: if (-not $(Test-Path -Path "$Path" -PathType Container)) { Write-Error -Message "Path ($Path) does not exist or is not a directory." -Categor…

Yep, the readability of PowerShell puts other shell scripting to shame. The "verbose default + short aliases" design is fantastic for maintaining both script readability and one-liner speed.

Re: Use long flags when scripting (2013)

#76
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.

Re: Use long flags when scripting (2013)

#78
post #21

Earlier quoted context omitted.

Long flags aren’t just for readability, they also add entropy which contributes defensiveness against typos.

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.

As does Python, which drives me crazy. -V is version on Python.

Re: Use long flags when scripting (2013)

#79
post #71

Earlier quoted context omitted.

... huh. No, no alias, I just misread the manpage. I could've sworn that -I was the default......

It's a common thing for IT departments or people making enterprise images to put in because they think it makes it safer. I feel it does more harm than good by normalising rm -f when you want to recursively delete a folder, but with CD deployments these days it's less of a deal.

Yeah... no. Also definitely not the case. If I actually am remembering it correctly then it's probably from Fedora circa FC5 or Ubuntu circa 6.06. Back when I was in school and had never touched Linux other than on my own computer.

Re: Use long flags when scripting (2013)

#80
post #40

Earlier quoted context omitted.

Particularly in this case, because `-v` sometimes means "print out the version number".

That's why they mentioned `grep -v`. Go look it up. It doesn't mean verbose OR version. Doubt you'd be printing out a version number in a shell script though.

>-v, --invert-match

> Selected lines are those not matching any of the specified patterns.

For the lazy.

Edit: I don't know hackernews formatting and I'm among the lazy, so... Marked as "won't fix".

Post reply on HN