xargs gives "[: err: unexpected operator" on Ubuntu but not Centos

Bug #1793668 reported by Roel Van de Paar
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
findutils (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

cd /tmp
rm -Rf tst err
echo 'if [ "$1" == "" ]; then echo "empty"; else cat $1; fi' > tst
chmod +x tst
echo "a" > err
ls err | xargs ./tst # ./tst: 1: [: err: unexpected operator
./tst err # works fine, outputs 'a'

On Ubuntu the error will be shown, on Centos it won't. The error looks to be incorrect.

$ lsb_release -rd
Description: Ubuntu 18.04.1 LTS
Release: 18.04
$ xargs --version
xargs (GNU findutils) 4.7.0-git
Copyright (C) 2017 Free Software Foundation, Inc.

Tags: bot-comment
description: updated
description: updated
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. It seems that your bug report is not filed about a specific source package though, rather it is just filed against Ubuntu in general. It is important that bug reports be filed about source packages so that people interested in the package can find the bugs about it. You can find some hints about determining what package your bug might be about at https://wiki.ubuntu.com/Bugs/FindRightPackage. You might also ask for help in the #ubuntu-bugs irc channel on Freenode.

To change the source package that this bug is filed about visit https://bugs.launchpad.net/ubuntu/+bug/1793668/+editstatus and add the package name in the text box next to the word Package.

[This is an automated message. I apologize if it reached you inappropriately; please just reply to this message indicating so.]

tags: added: bot-comment
affects: ubuntu → findutils (Ubuntu)
Changed in findutils (Ubuntu):
status: New → Confirmed
Revision history for this message
Andreas Metzler (k-launchpad-downhill-at-eu-org) wrote :

Hello,

tst is a shell script that does specify which interpreter should be used and therefore the system falls back to try /bin/sh.

However the script is using bash extensions ([ "$1" == "" ]) which won't work with *any* sh-type shell. Debian is using dash as /bin/sh and there an error is thrown, Centos is probably using bash.

So this is not a bug but a user error. If you want to use bash-extension you'll need to take care that the script runs under bash by using a correct #!-line.

Closing.

Changed in findutils (Ubuntu):
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.