azet / community_bash_style_guide

Community Bash Style Guide: writing useful and modern bash scripts, seriously.
Creative Commons Attribution 4.0 International
298 stars 37 forks source link

Better Multiline Pipe #12

Closed ldo closed 2 years ago

ldo commented 7 years ago

Instead of

ls ${long_list_of_parameters}   \
    | grep ${foo}               \
    | grep -v grep              \
    | pgrep                     \
    | wc -l                     \
    | sort                      \
    | uniq

how about

ls ${long_list_of_parameters} |
    grep ${foo} |
    grep -v grep |
    pgrep |
    wc -l |
    sort |
    uniq

which is less cluttered?

kallies commented 7 years ago

@ldo I like your approach. I've not used pipes for linebreaks. Does one see drawbacks?

Nitpicking: I'd prefer to have a "table" style format

ls ${long_list_of_parameters} |
    grep ${foo}               |
    grep -v grep              |
    pgrep                     |
    wc -l                     |
    sort                      |
    uniq
ldo commented 7 years ago

Lining things up in columns ... I have better things to do with my time.

kallies commented 7 years ago

It's a styleguide and should be understandable and pretty. Why don't spend the time creating a PR? :-)

azet commented 6 years ago

To be honest: this can be debated but I like the original/current recommendation (which is also used in other style guides), it's clearer from/to where the pipe flows.