Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xargs exits on empty line from stdin #435

Merged
merged 1 commit into from
Jan 31, 2024
Merged

Conversation

mknos
Copy link
Contributor

@mknos mknos commented Jan 31, 2024

  • BSD versions of xargs don't support the -l option
  • Standards document for xargs mentions -L but not -l [1]
  • Follow GNU version and accept -l as an alias for -L, but list standard -L in usage string
  • Behaviour of -L/-l didn't match xargs on my linux system: input loop was terminated on first empty line of STDIN
  • Skipping empty lines makes the behaviour match GNU version (empty means the line contains no non-spaces)
  1. https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/xargs.html
%cat -n in # not all lines have content
     1	#!/usr/bin/perl
     2	
     3	=begin metadata
     4	
     5	Name: awk
     6	Description: pattern-directed scanning and processing language
     7	Author: Tom Christiansen, tchrist@perl.com
     8	Author: Larry Wall, larry@wall.org
     9	License: perl
    10	

%xargs -L 1 < in # implicit 'echo' for each line of stdin
#!/usr/bin/perl
=begin metadata
Name: awk
Description: pattern-directed scanning and processing language
Author: Tom Christiansen, tchrist@perl.com
Author: Larry Wall, larry@wall.org
License: perl

%perl xargs -L 1 < in # patched version
#!/usr/bin/perl
=begin metadata
Name: awk
Description: pattern-directed scanning and processing language
Author: Tom Christiansen, tchrist@perl.com
Author: Larry Wall, larry@wall.org
License: perl

* BSD versions of xargs don't support the -l option
* Standards document for xargs mentions -L but not -l [1]
* Follow GNU version and accept -l as an alias for -L, but list standard -L in usage string
* Behaviour of -L/-l didn't match xargs on my linux system: input loop was terminated on
  first empty line of STDIN
* Skipping empty lines makes the behaviour match GNU version

1. https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/xargs.html

%cat -n in # not all lines have content
     1	#!/usr/bin/perl
     2	
     3	=begin metadata
     4	
     5	Name: awk
     6	Description: pattern-directed scanning and processing language
     7	Author: Tom Christiansen, tchrist@perl.com
     8	Author: Larry Wall, larry@wall.org
     9	License: perl
    10	

%xargs -L 1 < in # implicit 'echo' for each line of stdin
#!/usr/bin/perl
=begin metadata
Name: awk
Description: pattern-directed scanning and processing language
Author: Tom Christiansen, tchrist@perl.com
Author: Larry Wall, larry@wall.org
License: perl

%perl xargs -L 1 < in # patched version
#!/usr/bin/perl
=begin metadata
Name: awk
Description: pattern-directed scanning and processing language
Author: Tom Christiansen, tchrist@perl.com
Author: Larry Wall, larry@wall.org
License: perl
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: xargs The xargs program labels Jan 31, 2024
@briandfoy briandfoy self-assigned this Jan 31, 2024
@briandfoy briandfoy merged commit ca9a191 into briandfoy:master Jan 31, 2024
2 checks passed
@briandfoy briandfoy added Status: accepted The fix is accepted and removed Priority: low get to this whenever labels Jan 31, 2024
@briandfoy
Copy link
Owner

changes: -l is an alias for -L (GNU extension)

@briandfoy briandfoy added Status: released there is a new release with this fix and removed Status: accepted The fix is accepted labels Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: xargs The xargs program Status: released there is a new release with this fix Type: enhancement improve a feature that already exists
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants