Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
check_bindir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -2,7 +2,7 @@ bindir="$1" gitexecdir="$2" gitcmd="$3"-if test "$bindir" != "$gitexecdir" -a -x "$gitcmd"+if test "$bindir" != "$gitexecdir" && test -x "$gitcmd" then echo echo "!! You have installed git-* commands to new gitexecdir."
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
contrib/examples/git-commit.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -296,7 +296,7 @@ t,,,[1-9]*)die"No paths with -i does not make sense.";;esac-iftest!-z"$templatefile"-a-z"$log_given"+iftest!-z"$templatefile"&&test-z"$log_given"theniftest!-f"$templatefile"then
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
contrib/examples/git-merge.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
git-mergetool.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
git-submodule.sh | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
@@ -864,7 +864,7 @@ Maybe you want to use 'update --init'?")"thensubforce=$force# If we don't already have a -f flag and the submodule has never been checked out-iftest-z"$subsha1"-a-z"$force"+iftest-z"$subsha1"||test-z"$force"thensubforce="-f"fi
@@ -1059,13 +1059,13 @@ cmd_summary() {whilereadmod_srcmod_dstsha1_srcsha1_dststatussm_pathdo# Always show modules deleted or type-changed (blob<->module)-test$status=D-o$status=T&&echo"$sm_path"&&continue+(test$status=D||test$status=T)&&echo"$sm_path"&&continue# Respect the ignore setting for --for-status.iftest-n"$for_status"thenname=$(module_name"$sm_path")ignore_config=$(get_submodule_config"$name"ignorenone)-test$status!=A-a$ignore_config=all&&continue+test$status!=A&&test$ignore_config=all&&continuefi# Also show added or modified modules which are checked outGIT_DIR="$sm_path/.git"git-rev-parse--git-dir>/dev/null2>&1&&
@@ -1162,7 +1162,7 @@ cmd_summary() {# i.e. deleted or changed to blobtest$mod_dst=160000&&echo"$errmsg"else-iftest$mod_src=160000-a$mod_dst=160000+iftest$mod_src=160000&&test$mod_dst=160000thenlimit=test$summary_limit-gt0&&limit="-$summary_limit"
@@ -1402,7 +1402,7 @@ thenfi# "--cached" is accepted only by "status" and "summary"-iftest-n"$cached"&&test"$command"!=status-a"$command"!=summary+iftest-n"$cached"&&test"$command"!=status&&test"$command"!=summarythenusagefi
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
git-rebase--interactive.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -1013,7 +1013,7 @@ thengitrev-list$revisions|whilereadrevdo-iftest-f"$rewritten"/$rev-a"$(sane_grep"$rev""$state_dir"/not-cherry-picks)"=""+iftest-f"$rewritten"/$rev&&test"$(sane_grep"$rev""$state_dir"/not-cherry-picks)"=""then# Use -f2 because if rev-list is telling us this commit is# not worthwhile, we don't want to track its multiple heads,
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
git-bisect.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
contrib/examples/git-clone.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
contrib/examples/git-repack.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -76,8 +76,8 @@ case ",$all_into_one," inexisting="$existing$e"fidone-iftest-n"$existing"-a-n"$unpack_unreachable"-a\--n"$remove_redundant"+iftest-n"$existing"&&test-n"$unpack_unreachable"&&\+test-n"$remove_redundant"then# This may have arbitrary user arguments, so we# have to protect it against whitespace splitting
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
contrib/examples/git-resolve.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -76,7 +76,7 @@ case "$common" in2>/dev/null||continue# Count the paths that are unmerged.cnt=$(GIT_INDEX_FILE=$Ggitls-files--unmerged|wc-l)-iftest$best_cnt-le0-o$cnt-le$best_cnt+iftest$best_cnt-le0||test$cnt-le$best_cntthenbest=$cbest_cnt=$cnt
I am very sorry : the comment is wrong. I will repost shortly.
Best regards
2014-05-15 16:17 GMT+02:00 Elia Pinto [off-list ref]:
quoted hunk
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
git-submodule.sh | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
@@ -864,7 +864,7 @@ Maybe you want to use 'update --init'?")"thensubforce=$force# If we don't already have a -f flag and the submodule has never been checked out-iftest-z"$subsha1"-a-z"$force"+iftest-z"$subsha1"||test-z"$force"thensubforce="-f"fi
@@ -1059,13 +1059,13 @@ cmd_summary() {whilereadmod_srcmod_dstsha1_srcsha1_dststatussm_pathdo# Always show modules deleted or type-changed (blob<->module)-test$status=D-o$status=T&&echo"$sm_path"&&continue+(test$status=D||test$status=T)&&echo"$sm_path"&&continue# Respect the ignore setting for --for-status.iftest-n"$for_status"thenname=$(module_name"$sm_path")ignore_config=$(get_submodule_config"$name"ignorenone)-test$status!=A-a$ignore_config=all&&continue+test$status!=A&&test$ignore_config=all&&continuefi# Also show added or modified modules which are checked outGIT_DIR="$sm_path/.git"git-rev-parse--git-dir>/dev/null2>&1&&
@@ -1162,7 +1162,7 @@ cmd_summary() {# i.e. deleted or changed to blobtest$mod_dst=160000&&echo"$errmsg"else-iftest$mod_src=160000-a$mod_dst=160000+iftest$mod_src=160000&&test$mod_dst=160000thenlimit=test$summary_limit-gt0&&limit="-$summary_limit"
@@ -1402,7 +1402,7 @@ thenfi# "--cached" is accepted only by "status" and "summary"-iftest-n"$cached"&&test"$command"!=status-a"$command"!=summary+iftest-n"$cached"&&test"$command"!=status&&test"$command"!=summarythenusagefi--
From: Jonathan Nieder <hidden> Date: 2016-06-15 23:01:10
Elia Pinto wrote:
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
[... many lines snipped ...]
This is a very long description, and it doesn't leave me excited by
the change.
Is there some potential bug this prevents, or is it just a style
fix? If the latter, do we have a way of checking for new examples
of the same thing to avoid having to repeat the same patch again in
the future?
Are there any platforms that were broken which this fixes? Even
posh seems to understand -a and -o.
Nowadays Documentation/CodingGuidelines says
- Fixing style violations while working on a real change as a
preparatory clean-up step is good, but otherwise avoid useless code
churn for the sake of conforming to the style.
"Once it _is_ in the tree, it's not really worth the patch noise to
go and fix it up."
Cf. http://article.gmane.org/gmane.linux.kernel/943020
which I think goes too far (some patterns really are error prone
or distracting and it can be worth fixing them tree-wide), but it
makes a reasonable case that an idiom not being preferred in the
style guide is not *on its own* enough reason to change it.
Perhaps something like the following would work?
tree-wide: convert test -a/-o to && and ||
The interaction with unary operators and operator precedence
for && and || are better known than -a and -o, and for that
reason we prefer them. Replace all existing instances in git
of -a and -o to save readers from the burden of thinking
about such things.
Add a check-non-portable-shell.pl to avoid more instances of
test -a and -o arising in the future.
[...]
- test $status = D -o $status = T && echo "$sm_path" && continue
+ ( test $status = D || test $status = T ) && echo "$sm_path" && continue
There's no need for a subshell for this. Better to use a block:
{
test "$status" = D ||
test "$status" = T
} &&
echo "$sm_path" &&
continue
or an if statement:
if test "$status" = D || test "$status" = T
then
echo "$sm_path"
continue
fi
or case:
case $status in
D|T)
echo "$sm_path"
continue
;;
esac
Hope that helps,
Jonathan
From: David Aguilar <hidden> Date: 2016-06-15 23:01:12
On Thu, May 15, 2014 at 07:17:35AM -0700, Elia Pinto wrote:
Even though POSIX.1 lists -a/-o as options to "test", they are
marked "Obsolescent XSI". Scripts using these expressions
should be converted as follow:
test "$1" -a "$2"
should be written as:
test "$1" && test "$2"
Likewise
test "$1" -o "$2"
should be written as:
test "$1" test "$2"
But note that, in test, -a has higher precedence than -o while
"&&" and "||" have equal precedence in the shell.
The reason for this is that the precedence rules were never well
specified, and this made many sane-looking uses of "test -a/-o" problematic.
For example, if $x is "=", these work according to POSIX (it's not
portable, but in practice it's okay):
$ test -z "$x"
$ test -z "$x" && test a = b
but this doesn't
$ test -z "$x" -a a = b
bash: test: too many arguments
because it groups "test -n = -a" and is left with "a = b".
Similarly, if $x is "-f", these
$ test "$x"
$ test "$x" || test c = d
correctly adds an implicit "-n", but this fails:
$ test "$x" -o c = d
bash: test: too many arguments
Signed-off-by: Elia Pinto <redacted>
---
Inspired from this discussion http://permalink.gmane.org/gmane.comp.version-control.git/137056
Looks good, thanks.
Acked-by: David Aguilar <redacted>