Quote:
Originally Posted by rknichols
The "{" and "}" characters are special to
the shell only in certain constructs,
and a simple "{}" even unquoted is
not one of those constructs.
As an example, "{" can't begin a block of shell commands
unless it is followed by a whitespace character,
and "}" can't end the block unless there is a ";"
or newline following the last command in the block.
|
Thank you for trying to help.
But I am not able to follow your explanation.
For the underlined fragment above, can you link to some
rules on how to determine when a construct needs to be escaped?
Code:
As an example, "{" can't begin a block of
shell commands unless it is followed by
a whitespace character, and "}" can't end
the block unless there is a ";" or newline
following the last command in the block
Is the boldfaced sentence above the only rule?
As for "a block of shell commands" do you mean commands
to be processed by the shell or by the command
preceding the "block of shell commands"?
In your example, are you saying for such construct,
it needs to be escaped like so?
Code:
command1 option1A "{ command2 option2A option2B argument2A; }"
As I understand it, when we want to prevent
the shell from interpreting characters that
we want to pass on to its preceding command
(e.g. command1), we
escape those characters
with a backslash, enclose it with double quotes,
or single quotes.
I tried testing the first example without
escaping {}, and it still works.
Code:
~ $ find . -maxdepth 1 -type f -exec file {} \;
and I did not escape ";", and it produces and error.
Code:
~ $ find . -maxdepth 1 -type f -exec file {} ;
find: missing argument to `-exec'
So ";" is special to the shell and it was consumed by the shell
and was never passed to -exec.
A list of rules and types of character that MUST be escaped
(i.e. special to the shell) would clear things up.
Now I am even more confused!