As explained in your question's comments, the variable RELEASE_COMMAND_OUTPUT
will only get the STDOUT
(standard output) of your command but not the STDERR
(standard error), as it seems to be your case.
When in doubt about the output of your command you can use process substitution to mark the STDERR
in red as in the following example:
command 2> >(while read line; do echo -e "\e[01;31m$line\e[0m" >&2; done)
Which is redirecting (the 2>
part) the STDERR
of the command
as input to the while
block which will print it in red in the terminal.
You can also do the opposite, marking the STDOUT
as red with:
command | grep .
Because grep act only in STDOUT
NOTE: in some systems you may need to enable the color in grep using the flag --color=auto
. On Macos and Linux usually it's enable by default.
If using GNU mv
, you should rather do:
find . -type f -exec mv -t . {} +
With other mv
s:
find . -type f -exec sh -c 'exec mv "$@" .' sh {} +
You should never embed {}
in the sh
code. That's a command injection vulnerability as the names of the files are interpreted as shell code (try with a file called `reboot`
for instance).
Good point for quoting the command substitution, but because you used the archaic form (`...`
as opposed to $(...)
), you'd need to escape the inner double quotes or it won't work in sh
implementations based on the Bourne shell or AT&T ksh (where "`basename "foo bar"`"
would actually be treated as "`basename "
(with an unmatched `
which is accepted in those shells) concatenated with foo
and then bar"`"
).
Also, when you do:
mv foo/bar bar
If bar
actually existed and was a directory, that would actually be a mv foo/bar bar/bar
. mv -t . foo/bar
or mv foo/bar .
don't have that issue.
Now, to store those several arguments (-exec
, sh
, -c
, exec mv "$@" .
, sh
, {}
, +
) into a variable, you'd need an array variable. Shells supporting arrays are (t)csh
, ksh
, bash
, zsh
, rc
, es
, yash
, fish
.
And to be able to use that variable as just $FLATTEN
(as opposed to "${FLATTEN[@]}"
in ksh/bash/yash or $FLATTEN:q
in (t)csh
), you'd need a shell with a sane array implementation: rc
, es
or fish
. Also zsh
here as it happens none of those arguments is empty.
In rc
/es
/zsh
:
FLATTEN=(-exec sh -c 'exec mv "$@" .' sh '{}' +)
In fish
:
set FLATTEN -exec sh -c 'exec mv "$@" .' sh '{}' +
Then you can use:
find . -type f $FLATTEN
Best Answer
Using awk
awk works well for this:
The code above uses command substitution,
$(...)
, to capture the output of a command and assign it to a variable.In the code above, awk reads the output of
svn info
and waits for a line that contains the stringRevision:
. When that line is found, it prints the second field on that line, which is be the revision number.Using sed
It is also possible to do this using sed:
With the
-n
option, sed will only print when we explicitly ask it to./Revision:/
selects lines that contain the stringRevision:
. For those lines, a substitution command is performed that removes all characters up to the last blank on the line and then, due to thep
option, the line is printed.Using shell
The above uses redirection from process substition,
< <(...)
, to supply the output ofsvn info
to a while loop. For each iteration of the loop, the first word on the line is assigned toname
and the rest of the line is assigned tovalue
. Ifname
isRevision:
, then the shell variablevar
is assigned tovalue
, which is the revision number.Many, but not all, shells support process substitution. When, as above, redirection is combined with process substitution, the space between the two
<
is essential.