How about -execdir
?
This differs from -exec
in that it runs the command from the same directory that it finds the files (rather than the current working directory). Given that you're only going to find one translation.po
file in your LC_MESSAGES directories, we can lock things right down and not have to fuss around trying to snap the extension off the end of the path.
find . -name \*.po -execdir msgfmt translation.po -o translation.mo \;
Short Answer
Given the syntax $(command) &
, the result is the same as if you took the output of running just command
and then tried to run that as a command. And all of this would be done in the background, meaning that there would be no visible output or hanging in the terminal.
For example, if we had a text file named mycommand.txt
with the contents:
echo "Hello World"
Then the command
$(cat mycommand.txt) &
would be equivalent to running
echo "Hello World" &
But since we added the ampersand (&
), we wouldn't see any output from this command, so it would be pretty useless in this example.
Long Answer (Explanation)
Dollar sign $
(Variable)
The dollar sign before the thing in parenthesis usually refers to a variable. This means that this command is either passing an argument to that variable from a bash script or is getting the value of that variable for something. The difference in bash scripting for calling on and declaring variables goes as such:
Declare a variable without the dollar sign and call it with a dollar sign. For example, a script that contains this
#!/bin/bash
STR="Hello World!"
echo $STR
Would output this
Hello World!
Parenthesis ()
- Command substitution
Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed as follows:
$(command)
or
`command`
Bash performs the expansion by executing the command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat file)
can be replaced by the equivalent but faster $(< file)
.
Ampersand &
- Background process
And then the ampersand, or &
symbol, is as you said, used for running it in the background.
Best Answer
man bash
says:The last two lines are what is important: If you run
exec
by itself, without a command, it will simply make the redirections apply to the current shell. You probably know that when you runcommand > file
, the output ofcommand
is written tofile
instead of to your terminal (this is called a redirection). If you runexec > file
instead, then the redirection applies to the entire shell: Any output produced by the shell is written tofile
instead of to your terminal. For example hereI first start a new
bash
shell. Then, in this new shell I runexec > file
, so that all output is redirected tofile
. Indeed, after that I rundate
but I get no output, because the output is redirected tofile
. Then I exit my shell (so that the redirection no longer applies) and I see thatfile
indeed contains the output of thedate
command I ran earlier.