Re: Can someone explain this?

2011-02-12 Thread Andreas Schwab
Bob Proulx  writes:

> Dennis Williamson wrote:
>> Yes, do your quoting like this:
>> ssh localhost 'bash -c "cd /tmp; pwd"'
>
> I am a big fan of piping the script to the remote shell.
>
>   $ echo "cd /tmp && pwd" | ssh example.com bash
>   /tmp

Even better:

$ ssh example.com bash <<\EOF
cd /tmp && pwd
EOF

That avoids having to watch out for ' vs " quoting.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



leading 0 inconsistence?

2011-02-12 Thread Ralf Goertz
Hi,

I am wondering what the reasoning might be for this seeming
inconsistence.

> i=08
> if [ $i -lt 9 ] ; then echo ok; fi
ok
> if [ $((i)) -lt 9 ] ; then echo ok; fi
bash: 08: value too great for base (error token is "08")

Why is 08 not tried to be interpreted as octal when *numerically* compared
using test?




Re: leading 0 inconsistence?

2011-02-12 Thread Andreas Schwab
Ralf Goertz  writes:

> Why is 08 not tried to be interpreted as octal when *numerically* compared
> using test?

Because test does not know about octal for compatibility.  Use [[ ... ]]
if you want to be closer to $((...)).

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Corrupt prompt string using '\W' within PS1

2011-02-12 Thread Thomas Kuschel

From: oe6...@gmx.at
To: bug-bash@gnu.org
Subject: Corrupt prompt string using '\W' within PS1

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' 
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include 
-I./lib   -g -O2
uname output: Linux gold 2.6.32-5-amd64 #1 SMP Fri Dec 10 15:35:08 UTC 
2010 x86_64 GNU/Linux

Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.1
Patch Level: 9
Release Status: release

Description:
Corrupt prompt string using the backslash-escaped special character 
'\W'


Repeat-By:
When executing interactively bash displays the following sequence:
  bash-4.1$ cd /
  bash-4.1$ PS1="\W \$ "
  / $ cd home
  hmee $ cd /media
  meiia $

Fix:
Inside 'y.tab.c' the use of strcpy is in undefined behavior.
The 't_string' and 't' objects overlaps. Using the memmove,
copying takes place as if an intermediate buffer was used,
allowing the destination and source to overlap.
Regards,

Thomas Kuschel, oe6tkt

--- old/y.tab.c2009-12-30 18:52:02.0 +0100
+++ y.tab.c2011-02-11 12:36:45.682266575 +0100
@@ -7481,7 +7481,10 @@ decode_prompt_string (string)
   {
 t = strrchr (t_string, '/');
 if (t)
-  strcpy (t_string, t + 1);
+  /* strcpy: If copying takes place between objects that 
overlap,

+ the behavior is undefined.
+strcpy (t_string, t + 1); so changed to: */
+  memmove (t_string; t + 1, strlen (t));
   }
   }
 #undef ROOT_PATH
--- old/y.tab.c	2009-12-30 18:52:02.0 +0100
+++ y.tab.c	2011-02-11 12:36:45.682266575 +0100
@@ -7481,7 +7481,10 @@ decode_prompt_string (string)
 		  {
 			t = strrchr (t_string, '/');
 			if (t)
-			  strcpy (t_string, t + 1);
+			  /* strcpy: If copying takes place between objects that overlap,
+			 the behavior is undefined.
+strcpy (t_string, t + 1); so changed to: */
+			  memmove (t_string; t + 1, strlen (t));
 		  }
 		  }
 #undef ROOT_PATH


Re: Can someone explain this?

2011-02-12 Thread Maarten Billemont
On 12 Feb 2011, at 09:28, Andreas Schwab wrote:
> 
> Bob Proulx  writes:
> 
>> Dennis Williamson wrote:
>>> Yes, do your quoting like this:
>>> ssh localhost 'bash -c "cd /tmp; pwd"'
>> 
>> I am a big fan of piping the script to the remote shell.
>> 
>>  $ echo "cd /tmp && pwd" | ssh example.com bash
>>  /tmp
> 
> Even better:
> 
> $ ssh example.com bash <<\EOF
> cd /tmp && pwd
> EOF
> 
> That avoids having to watch out for ' vs " quoting.
> 
> Andreas.

The trouble with using stdin is that it becomes much harder to pass user data.

If it's simple strings, one might be tempted to expand them instead:

ssh example.com bash <

Re: leading 0 inconsistence?

2011-02-12 Thread Maarten Billemont
On 12 Feb 2011, at 11:57, Ralf Goertz wrote:
> 
> Hi,
> 
> I am wondering what the reasoning might be for this seeming
> inconsistence.
> 
>> i=08
>> if [ $i -lt 9 ] ; then echo ok; fi
> ok
>> if [ $((i)) -lt 9 ] ; then echo ok; fi
> bash: 08: value too great for base (error token is "08")
> 
> Why is 08 not tried to be interpreted as octal when *numerically* compared
> using test?
> 
> 

I stand by my general recommendation of always using (( when performing 
arithmetic tests, [[ when testing strings and files, and never [, unless your 
shebang is not actually bash.  It will save you from a great many pitfalls and 
inconsistencies.




Re: PS1 has ruined line wrap

2011-02-12 Thread Jonathan Reed
An old thread but I found a way around this by adding a line to my bashrc:

echo -ne "\033]0; `whoami` @ `hostname` \007"

The reference
http://mdinh.wordpress.com/2010/11/21/xterm-title-bar/

On Thu, Nov 25, 2010 at 7:26 PM, Chet Ramey  wrote:

> On 11/25/10 3:38 PM, Jonathan Reed wrote:
> > I was using this as my ps1
> > PS1='[\u@\[\e[1;31m\]\h\[\e[0m\]:$PWD]\$ '
> >
> > But I wanted to label the title of my xterm windows with the hostname of
> > system Im logged into. So I added the following
> > PS1='[\u@\[\e[1;45m\]\h\[\e[0m\] $PWD]\e]2;@ \H\a\$ '
> >
> > It works great except for it rewrites the current line if I write text
> past
> > the current window size (regardless of the window size).
> > filenameERVERNAME:/home/jreed]$ cat /a/really/long_fi
> >
> > Any suggestions?
>
> You might consider bracketing all sequences of non-printing characters
> with \[ and \].
>
>
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, ITS, CWRUc...@case.edu
> http://cnswww.cns.cwru.edu/~chet/
>