|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I'm starting to use bash and just trying a few things out from the man page.
The following doesn't work as I expected it to (in cygwin under win2K): #! /bin/bash cd / echo line 1 echo `date` `dir` echo line 2 echo `d{ate`,ir`} Output is: $ ./syntest.txt line 1 Sat Dec 11 22:23:45 WEST 2004 bin cygwin.ico etc install ma int tmp var cygwin.bat data home lib ratmaint usr line 2 ./syntest.txt: line 6: unexpected EOF while looking for mat ching ``' ./syntest.txt: line 7: syntax error: unexpected end of file I was expecting the same output from the last line and the one two lines before. Why doesn't brace expansion produce the matching "`" before command substitution requires it to match? (Note "`" doesn't count as a word separator if I understand the "DEFINITIONS" section correctly. I am assuming a single quote means "'" rather than "`".) What am I missing? Some relevant bits of the man page: DEFINITIONS ... metacharacter A character that, when unquoted, separates words. One of the following: | & ; ( ) < > space tab QUOTING ... Each of the metacharacters listed above under DEFINITIONS has special meaning to the shell and must be quoted if they are to represent themselves. There are three quoting mechanisms: the escape character, single quotes, and double quotes. EXPANSION Expansion is performed on the command line after it has been split into words. There are seven kinds of expansion per- formed: ... The order of expansions is: brace expansion, tilde expansion, parameter, variable, command, and arithmetic substitution ... ... Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces. |
|
#2
|
|||
|
|||
|
Command substitution is done first. The stuff between backticks goes off to a subshell to be executed. The results are gathered and replace the backticked expression. Two different shells can't work together on a brace expansion.
You can achieve this result by re-ordering the sequence in which things are done. Rather than dir, I tested this with df. eval echo \`d{ate\`,f\`} |
|
#3
|
|||
|
|||
|
Quote:
Thanks for this excellent reply and yes, what you say must be correct - your example works fine. I must say that the man page is to say the least confusing on this. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > bash - very basic syntax question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|