Bug 340291
Summary: | test -n doesnt work | ||||||
---|---|---|---|---|---|---|---|
Product: | [Fedora] Fedora | Reporter: | Stas Sergeev <stsp2> | ||||
Component: | coreutils | Assignee: | Pete Graner <pgraner> | ||||
Status: | CLOSED NOTABUG | QA Contact: | Fedora Extras Quality Assurance <extras-qa> | ||||
Severity: | low | Docs Contact: | |||||
Priority: | low | ||||||
Version: | 7 | CC: | ivazqueznet, twaugh | ||||
Target Milestone: | --- | ||||||
Target Release: | --- | ||||||
Hardware: | All | ||||||
OS: | Linux | ||||||
Whiteboard: | |||||||
Fixed In Version: | Doc Type: | Bug Fix | |||||
Doc Text: | Story Points: | --- | |||||
Clone Of: | Environment: | ||||||
Last Closed: | 2007-10-22 08:26:17 UTC | Type: | --- | ||||
Regression: | --- | Mount Type: | --- | ||||
Documentation: | --- | CRM: | |||||
Verified Versions: | Category: | --- | |||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
Cloudforms Team: | --- | Target Upstream Version: | |||||
Embargoed: | |||||||
Attachments: |
|
Description
Stas Sergeev
2007-10-19 18:27:08 UTC
Created attachment 232901 [details]
the test case
Are you invoking test(1) or bash's built-in test command? test(1) from coreutils. And using explicitly /usr/bin/test gives the same, and [ ] too. You are supplying more than one parameter. "$@" expands to one word per argument, i.e. $# words. Perhaps one of those words is a test option. Looks like you probably want "$*" there. > You are supplying more than one parameter. Where? I run the script without any parameters. > "$@" expands to one word per argument, i.e. $# words. OKey, echo $# from that script gives 0. And echo -n "$@" >a gives a zero-sized file. > Perhaps one of those words is a test option. Have you tried starting the script? I am not trying to cheat you by supplying one of the "test" options as a parameter to the script - that would be a waste of time. Instead, I made sure "$@" is empty by echoing it into a file. > Looks like you probably want "$*" there. My point is that test "$@" and test -n "$@" gives different results, while the man states they are the same. This is clearly demonstrated by my script. Can you explain that difference? What I'm saying is that "$@" is special. In the case where there are no arguments supplied, it is 0 words, i.e. it is replaced by absolutely nothing, not even an empty string. So 'test "$@"' is not testing a string, it is testing *nothing*, so is trivially true. Not a bug -- use "$*". But that does not answer my question why 'test -n "$@"' and 'test "$@"' give the different results. If it is not the bug, then at least the documentation is wrong, because it says its the same. > it is replaced by absolutely nothing, > not even an empty string. Aren't the " around the nothing makes it an empty string btw? > So 'test "$@"' is not testing a string, > it is testing *nothing*, so is trivially > true. No, 'test "$@"' is exactly false, but 'test -n "$@"' is true. (In reply to comment #8) > > it is replaced by absolutely nothing, > > not even an empty string. > Aren't the " around the nothing makes > it an empty string btw? No. "$@" is special-cased in bash. If there are no parameters then it evaluates to nothing, not even an empty string. > No. "$@" is special-cased in bash.
Ah, ok then. And 'test' without any parameters
returns false, right?
Thank you both for the explanations.
|