Stories
Slash Boxes
Comments

SoylentNews is people

SoylentNews is powered by your submissions, so send in your scoop. Only 17 submissions in the queue.
posted by martyb on Tuesday December 01 2015, @07:50PM   Printer-friendly
from the features-are-beneficial-bugs dept.

We make very careful considerations about the interface and operation of the GNU coreutils, but unfortunately due to backwards compatibility reasons, some behaviours or defaults of these utilities can be confusing.

This information will continue to be updated and overlaps somewhat with the coreutils FAQ, with this list focusing on less frequent potential issues.

Good tips and reminders for those who don't work mostly with a CLI (Command Line Interface).


[What has been YOUR biggest CLI gotcha? -Ed.]

Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 1) by shipofgold on Tuesday December 01 2015, @08:54PM

    by shipofgold (4696) on Tuesday December 01 2015, @08:54PM (#270350)

    I always like the philosophy of Rob Pike as detailed at:

    http://harmful.cat-v.org/cat-v/ [cat-v.org]

    I still like commands with few options to which you can send output to other filters to get what you need. tar never needed the -x or -j or -J options.

    My favorite gotcha is the difference between the for loop and the while loop in bash. While loops create subshells with a new environment while for loops do not. Makes changes to bash variables very interesting.

  • (Score: 3, Informative) by draconx on Tuesday December 01 2015, @09:10PM

    by draconx (4649) on Tuesday December 01 2015, @09:10PM (#270352)

    My favorite gotcha is the difference between the for loop and the while loop in bash. While loops create subshells with a new environment while for loops do not. Makes changes to bash variables very interesting.

    This is not the case. Neither for nor while loops create a subshell.

    % echo $BASH_VERSION
    4.3.39(1)-release
     
    % s=; while :; do s=while_is_not_a_subshell; break; done
    % printf '%s\n' "$s"
    while_is_not_a_subshell
     
    % s=; for x in x; do s=for_is_not_a_subshell; break; done
    % printf '%s\n' "$s"
    for_is_not_a_subshell

    • (Score: 0) by Anonymous Coward on Tuesday December 01 2015, @09:33PM

      by Anonymous Coward on Tuesday December 01 2015, @09:33PM (#270363)

      This is not the case. Neither for nor while loops create a subshell.

      It appears that while loops do: Bash Subshells [tldp.org]

      • (Score: 0) by Anonymous Coward on Tuesday December 01 2015, @09:35PM

        by Anonymous Coward on Tuesday December 01 2015, @09:35PM (#270364)

        Never mind, I just noticed that the while was enclosed in a ( ), which where the subshell comes from...

  • (Score: 5, Funny) by wonkey_monkey on Tuesday December 01 2015, @10:40PM

    by wonkey_monkey (279) on Tuesday December 01 2015, @10:40PM (#270380) Homepage

    while for loops do not

    Eh, so confused. I'm done.

    --
    systemd is Roko's Basilisk
  • (Score: 0) by Anonymous Coward on Tuesday December 01 2015, @10:42PM

    by Anonymous Coward on Tuesday December 01 2015, @10:42PM (#270381)

    tar never needed the -x or -j or -J options.

    (I'm gonna assume you mean -X instead of -x since a tar that can't extract files is pretty useless!)

    tar's command line is pretty bad to begin with [xkcd.com]. I prefer pax; too bad most distros don't ship it by default even though it's POSIX.

  • (Score: 2, Informative) by xav on Wednesday December 02 2015, @03:55AM

    by xav (5579) on Wednesday December 02 2015, @03:55AM (#270481)

    My favorite gotcha is the difference between the for loop and the while loop in bash. While loops create subshells with a new environment while for loops do not.

    No, pipes do create subshells, not "while".

    What I mean is that
    # seq 1 3 | while read n; do echo $n; done
    creates two subshells for seq and while, whereas
    # for n in $(seq 1 3); do echo $n; done
    creates only one subshell for seq, not for the "for" loop.

    On the other hand, the two following while loops do the same thing in the current shell:
    # while read n; do echo $n; done <<< "$(seq 1 3)"
    # while read n; do echo $n; done < <(seq 1 3)