Skip to content

Commit

Permalink
ls: -1 for non-tty
Browse files Browse the repository at this point in the history
* The manual explains that if output is not a tty, ls will infer the -1 flag (i.e. print one entry per line)
* The old filemode check code did not work on my Linux system but this patch does
* I tested this with a pipe into cat, and with a redirect into a file
  • Loading branch information
mknos authored Jun 26, 2024
1 parent 7836a41 commit a87f2ca
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions bin/ls
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,7 @@ unless (getopts('1ACFLRSTWacdfgiklmnopqrstux', \%Options)) {
if ($Options{'f'}) {
$Options{'a'} = 1;
}

$Attributes = stat(*STDOUT);
if ($Attributes->mode & 0140000) {
$Options{'1'} = '1';
}
$Options{'1'} = 1 unless (-t *STDOUT);

# ------ current directory if no arguments
if ($#ARGV < 0) {
Expand Down

0 comments on commit a87f2ca

Please sign in to comment.