I'm on a wsl Ubuntu 20.04 and cannot comprehend why my command does not seem to take into account my first parameter as if it has trouble interpreting the quotes. Any idea on what is going on here? Thanks in advance for your help
CodePudding user response:
As already mentioned in the comments, |
is a pipe, so any output of git tag -l
is piped to echo
and because echo
does not really read the input, just ignores it, all you get is "HELLO".
The OR operator, ||
, is probably what you want, although it won't work just like that with git tag -l
, because that command returns success even if there are no tags. But in the comments you mention that what you actually want is git tag -d TAG
. That should work fine, because it returns failure when TAG does not exist.
You also worry that using OR operator would prematurely stop processing your modules. The opposite is actually true. From the documentation:
A non-zero return from the command in any submodule causes the processing to terminate. This can be overridden by adding || : to the end of the command.
So without ||
the processing will stop on the first submodule, which doesn't have TAG.
In case you want it to work with git tag -l
too, you have to somehow make it return failure if there are no tags. One way, maybe not the best, is pipe its output to grep ".*"
. Some example:
]$ git submodule foreach 'git tag -l "v5.0*beta1" | grep ".*" || echo "NOT FOUND"'
Entering 'qtactiveqt'
v5.0.0-beta1
Entering 'qtbase'
NOT FOUND
Entering 'qtqa'
v5.0.0-beta1
Entering 'qtrepotools'
v5.0.0-beta1