UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 11th, 2004, 03:54 PM
roobaarb roobaarb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 17 roobaarb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 8 m 46 sec
Reputation Power: 0
Post bash - very basic syntax question

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.

Reply With Quote
  #2  
Old December 12th, 2004, 01:06 AM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
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\`}

Reply With Quote
  #3  
Old December 12th, 2004, 05:12 AM
roobaarb roobaarb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 17 roobaarb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 8 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by Perderabo
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\`}

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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > bash - very basic syntax question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway