Re: [expert] Riddle

2002-11-22 Thread Guillaume Marcais
On Fri, 2002-11-22 at 14:56, Todd Lyons wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> ath1410 wrote on Fri, Nov 22, 2002 at 05:04:55PM +0900 :
> > 
> > I checked the sites you refered, but did not still quite figure
> > out (partly because of my poor English?) the way bash works the
> > way it does. To make things simple, just take up one case here.
> > $PS1=u   -4  returns \u
> > the 1st \ escapes the 2nd \, and the 3rd one to the 4th one
> > likewise.
> > So  $PS1=u is something like $PS1='\\u' ( which actually
> > returns \u, not user name.
> 
> Yes.
> 
> The following are identical:
> PS=u
> PS="u"
> 
> 
> This is NOT the same:
> PS='u'
> 
> Nor seemingly is this because of the single quoting which prevents
> parameter expansion.  I honestly thought it _would_ be the same, but if
> you say it doesn't work, then it doesn't work:
> PS='\\u'
> 
> The trick is that bash parses each commandline twice (repeating someone
> else's authoritative post from memory, so anybody more knowledgable,
> please feel free to correct errors).  The first time it converts "\\" to
> "\" and "\\" to "\", leaving you with "\\u".  The second time it
> converts "\\" to "\", leaving you with "\u".  That is what then gets
> used.

Actually no, it is parsed 3 times: once when you enter it not quoted in
the command line, a second time by the prompting decoding (only certain
specific backslah substitutions performed) and a third time if you
variable promptvars is set (set by default, see shopt). This explain the
small number of \ in the display prompt compared to what you used in the
command line.

Guillaume.


> Blue skies... Todd
> - -- 
>MandrakeSoft USA   http://www.mandrakesoft.com
>   cat /boot/vmlinuz > /dev/dsp  #for great justice
>Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-0.2mdk
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.2.1 (GNU/Linux)
> 
> iD8DBQE93ovilp7v05cW2woRAvyzAJ4sSqW6ez0W0GgYdIWGFMKs30zU1QCgrQxl
> ilYHcg/BLdcHjVTiGikMhaE=
> =LR3p
> -END PGP SIGNATURE-
> 
> 
> 

> Want to buy your Pack or Services from MandrakeSoft? 
> Go to http://www.mandrakestore.com




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] Riddle

2002-11-22 Thread Todd Lyons
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

ath1410 wrote on Fri, Nov 22, 2002 at 05:04:55PM +0900 :
> 
> I checked the sites you refered, but did not still quite figure
> out (partly because of my poor English?) the way bash works the
> way it does. To make things simple, just take up one case here.
> $PS1=u   -4  returns \u
> the 1st \ escapes the 2nd \, and the 3rd one to the 4th one
> likewise.
> So  $PS1=u is something like $PS1='\\u' ( which actually
> returns \u, not user name.

Yes.

The following are identical:
PS=u
PS="u"


This is NOT the same:
PS='u'

Nor seemingly is this because of the single quoting which prevents
parameter expansion.  I honestly thought it _would_ be the same, but if
you say it doesn't work, then it doesn't work:
PS='\\u'

The trick is that bash parses each commandline twice (repeating someone
else's authoritative post from memory, so anybody more knowledgable,
please feel free to correct errors).  The first time it converts "\\" to
"\" and "\\" to "\", leaving you with "\\u".  The second time it
converts "\\" to "\", leaving you with "\u".  That is what then gets
used.

Blue skies...   Todd
- -- 
   MandrakeSoft USA   http://www.mandrakesoft.com
  cat /boot/vmlinuz > /dev/dsp  #for great justice
   Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-0.2mdk
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE93ovilp7v05cW2woRAvyzAJ4sSqW6ez0W0GgYdIWGFMKs30zU1QCgrQxl
ilYHcg/BLdcHjVTiGikMhaE=
=LR3p
-END PGP SIGNATURE-


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] Riddle

2002-11-22 Thread Larry Sword
ath1410 wrote:

>tks, Mr Larry.
>
>I checked the sites you refered, but did not still quite figure
>out (partly because of my poor English?) the way bash works the
>way it does. To make things simple, just take up one case here.
>
>$PS1=u   -4  returns \u
>
>the 1st \ escapes the 2nd \, and the 3rd one to the 4th one
>likewise.
>
>So  $PS1=u is something like $PS1='\\u' ( which actually
>returns \u, not user name.
>
>It seems to me that when bash handles $PS1='\\u', 1st \ escapes
>the 2nd one and  $PS1='\\u' seems equal to $PS1='\u' which
>returns user name.
>
>How shell recognize $PS1='\\u' and how shell return \u, not a
>user name?
>
>This problem is pestering me for 3 whole days. Please help!
>

Not sure I can the language is a problem linux HOWTO's are available in
most languages including Japanese @:
http://www.ibiblio.org/pub/Linux/docs/HOWTO/translations/ja/

Hopefully this will help.

Larry

>
>
>
>
>
>
>  
>
>>Larry Sword wrote:
>>
>>
>>
>>>ath1410 wrote:
>>>
>>> 
>>>
>>>  
>>>
Can someone help! I have been trying to explain the way bash
works as follows.

$PS1=\\u -2  returns user
$PS1=\\\u-3  returns user
$PS1=u   -4  returns \u
$PS1=\u  -5  returns \u
$PS1=\\u -6  returns \user
$PS1=\\\u-7  returns \user
$PS1=u   -8  returns \u
$PS1=\u  -9  returns \u
$PS1=\\u-10  returns \user
$PS1=\\\u   -11  returns \user
$PS1=u  -12  returns \\u

I can understand somewhere around;

$PS1=\\\u-3  returns user

But more than that, I can't figure out why bash respond
as it does. What the logic behind it?



   



>>>Review the two HOWTO's:
>>>
>>>1. BASH Programming-Introduction HOW-TO
>>>
>>>and
>>>
>>>2. From Power Up to Bash Prompt
>>>
>>>  
>>>
>>Should be: Bash Prompt HOWTO @ 
>>http://www.linuxselfhelp.com/HOWTO/Bash-Prompt-HOWTO/
>>
>>
>>
>>>This probable is answered as a string comparsion operators.
>>>
>>>Larry
>>>  
>>>
>  
>




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] Riddle

2002-11-22 Thread ath1410
tks, Mr Larry.

I checked the sites you refered, but did not still quite figure
out (partly because of my poor English?) the way bash works the
way it does. To make things simple, just take up one case here.

$PS1=u   -4  returns \u

the 1st \ escapes the 2nd \, and the 3rd one to the 4th one
likewise.

So  $PS1=u is something like $PS1='\\u' ( which actually
returns \u, not user name.

It seems to me that when bash handles $PS1='\\u', 1st \ escapes
the 2nd one and  $PS1='\\u' seems equal to $PS1='\u' which
returns user name.

How shell recognize $PS1='\\u' and how shell return \u, not a
user name?

This problem is pestering me for 3 whole days. Please help!






>
>Larry Sword wrote:
>
>>ath1410 wrote:
>>
>>  
>>
>>>Can someone help! I have been trying to explain the way bash
>>>works as follows.
>>>
>>>$PS1=\\u -2  returns user
>>>$PS1=\\\u-3  returns user
>>>$PS1=u   -4  returns \u
>>>$PS1=\u  -5  returns \u
>>>$PS1=\\u -6  returns \user
>>>$PS1=\\\u-7  returns \user
>>>$PS1=u   -8  returns \u
>>>$PS1=\u  -9  returns \u
>>>$PS1=\\u-10  returns \user
>>>$PS1=\\\u   -11  returns \user
>>>$PS1=u  -12  returns \\u
>>>
>>>I can understand somewhere around;
>>>
>>>$PS1=\\\u-3  returns user
>>>
>>>But more than that, I can't figure out why bash respond
>>>as it does. What the logic behind it?
>>>
>>> 
>>>
>>>
>>>
>>Review the two HOWTO's:
>>
>>1. BASH Programming-Introduction HOW-TO
>>
>>and
>>
>>2. From Power Up to Bash Prompt
>>
>Should be: Bash Prompt HOWTO @ 
>http://www.linuxselfhelp.com/HOWTO/Bash-Prompt-HOWTO/
>
>>
>>This probable is answered as a string comparsion operators.
>>
>>Larry
>
>
>Want to buy your Pack or Services from MandrakeSoft? 
>Go to http://www.mandrakestore.com

+-+ * Get your own Jmail account.|URL= http://www.jmail.co.jp
|--jmail--| * Get your own home page.|URL= http://www.servance.jp
+-+ * Get your own domain.|URL= http://domaintorou.com/


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] Riddle

2002-11-21 Thread Larry Sword
Larry Sword wrote:


ath1410 wrote:

 

Can someone help! I have been trying to explain the way bash
works as follows.

$PS1=\\u -2  returns user
$PS1=\\\u-3  returns user
$PS1=u   -4  returns \u
$PS1=\u  -5  returns \u
$PS1=\\u -6  returns \user
$PS1=\\\u-7  returns \user
$PS1=u   -8  returns \u
$PS1=\u  -9  returns \u
$PS1=\\u-10  returns \user
$PS1=\\\u   -11  returns \user
$PS1=u  -12  returns \\u

I can understand somewhere around;

$PS1=\\\u-3  returns user

But more than that, I can't figure out why bash respond
as it does. What the logic behind it?



   

Review the two HOWTO's:

1. BASH Programming-Introduction HOW-TO

and

2. From Power Up to Bash Prompt


Should be: Bash Prompt HOWTO @ 
http://www.linuxselfhelp.com/HOWTO/Bash-Prompt-HOWTO/


This probable is answered as a string comparsion operators.

Larry







 



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com
 






Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] Riddle

2002-11-21 Thread Larry Sword
ath1410 wrote:

>Can someone help! I have been trying to explain the way bash
>works as follows.
>
>$PS1=\\u -2  returns user
>$PS1=\\\u-3  returns user
>$PS1=u   -4  returns \u
>$PS1=\u  -5  returns \u
>$PS1=\\u -6  returns \user
>$PS1=\\\u-7  returns \user
>$PS1=u   -8  returns \u
>$PS1=\u  -9  returns \u
>$PS1=\\u-10  returns \user
>$PS1=\\\u   -11  returns \user
>$PS1=u  -12  returns \\u
>
>I can understand somewhere around;
>
>$PS1=\\\u-3  returns user
>
>But more than that, I can't figure out why bash respond
>as it does. What the logic behind it?
>
>  
>
Review the two HOWTO's:

1. BASH Programming-Introduction HOW-TO

and

2. From Power Up to Bash Prompt

This probable is answered as a string comparsion operators.

Larry








Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com