Word splitting and arithmetic expansion

2010-12-28 Thread Jan Schampera

Hello list,

maybe something for old stagers.

Bash (and POSIX, and Korn, ...) do field/word splitting on the result of 
arithmetic expansions. This is fine, the behaviour per se is not a 
problem at all.


However, I wonder about the original thought behind it: Is there a 
specific reason or need to let the shell split an arithmetic expansion 
result? Or was it just consistency for Korn, "everything is splitted, 
except the expansions where it makes no sense, like pathname expansion" 
- should I just take it "as is"? Or even older shells that split everything?


Neither the POSIX rationale nor older Korn or shell portability 
documents I found had any hint about the background - maybe you have?


--
Be conservative in what you do, be liberal in what you accept from others.
- jbp, master of the net, in RFC793




Re: Word splitting and arithmetic expansion

2010-12-28 Thread Chet Ramey
On 12/28/10 2:50 PM, Jan Schampera wrote:
> Hello list,
> 
> maybe something for old stagers.
> 
> Bash (and POSIX, and Korn, ...) do field/word splitting on the result of
> arithmetic expansions. This is fine, the behaviour per se is not a problem
> at all.
> 
> However, I wonder about the original thought behind it: Is there a specific
> reason or need to let the shell split an arithmetic expansion result?

Arithmetic expansion is a Posix invention.  It's treated just like every
other expansion: split unless double quoted.  There's no compelling
reason to make it behave differently.

> was it just consistency for Korn, "everything is splitted, except the
> expansions where it makes no sense, like pathname expansion"

Pathname expansion happens after word splitting.  Tilde expansion is the
one that's not subject to word splitting.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



how to escape single quote?

2010-12-28 Thread ali hagigat
I wonder if anybody knows how to escape a single quote character by
/bin/sh or bash?
echo 'ppp\'qqq''
ppp\qqq
Please look at the above example and the result.
Regards



Re: how to escape single quote?

2010-12-28 Thread Mart Frauenlob

On 29.12.2010 08:28, ali hagigat wrote:

I wonder if anybody knows how to escape a single quote character by
/bin/sh or bash?
echo 'ppp\'qqq''
ppp\qqq
Please look at the above example and the result.
Regards



from man bash:

Enclosing  characters  in  single  quotes  preserves  the  literal value 
of each character within the quotes.
A single quote may not occur between single quotes, even when preceded 
by a backslash.