You are not logged in.
Maybe it's never been great bash scripting, but I've most often used `test` explicitly for what seems to provide better readability,
but since recently(since bash 5.1?) some of my scripts no longer work...
For example, something like the following (greatly simplified):
if test $(hg summary | grep -q heads); then echo 'rebase needed'; fi
doesn't work anymore
but simply
if $(hg summary | grep -q heads); then echo 'rebase needed'; fi
does.
Is this a lesson in fixing bad scripts or perhaps a new bug?
Offline
if test $(hg summary | grep -q heads)
Unless that command between $(…) produces a valid sequence of strings that can be passed as arguments to test, that has never been valid bash (or sh in general) scripting. And IMHO it doesn't help readability at all (at least for someone knowing shell scripting…)
From what I can see, that will actually never do the `then` part, because `grep -q` will not output anything, and so no argument is passed to `test`, resulting in it always exiting with a non-zero return code.
I believe you wanted this instead:
if hg summary | grep -q heads; then …
Offline
yeah, cockpit error... thx
Offline
# hg summary | grep -q heads && { echo "rebase"; }
Same result, less typing maybe.
Offline