Variable passed to system contains garbage characters

2007-12-17 Thread Patrick Nagelschmidt

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include 
-I./lib  -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 
-g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic 
-fasynchronous-unwind-tables
uname output: Linux DL.second 2.6.23.1 #1 Sun Oct 21 17:49:04 CEST 
2007 i686 athlon i386 GNU/Linux

Machine Type: i686-redhat-linux-gnu

Bash Version: 3.2
Patch Level: 33
Release Status: release

Description:
The script below fails on my box with the following output:

1197676800
date: invalid date `1970-01-01 \033[?1034h1197676800 sec'

So for some reason the value passed to date got a nasty prefix.

I guess this could be charset-related, so here's my locale

LANG=en_US
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=

Repeat-By:
executing this script

#!/bin/bash
let "STEP=86400"
let "CALCTIME=`date +%s`"
export DAYSTART=`echo "$CALCTIME - ($CALCTIME % $STEP) - 
$STEP" |bc -i |tail -1`

echo "$DAYSTART"
export BASHBUG=`date -d "1970-01-01 $DAYSTART sec" +"%Y-%m-%d %T"`

Fix:
Yes, please ;)





Re: Variable passed to system contains garbage characters

2007-12-17 Thread Chet Ramey
Patrick Nagelschmidt wrote:
> Machine Type: i686-redhat-linux-gnu
> 
> Bash Version: 3.2
> Patch Level: 33
> Release Status: release
> 
> Description:
> The script below fails on my box with the following output:
> 
> 1197676800
> date: invalid date `1970-01-01 \033[?1034h1197676800 sec'
> 
> So for some reason the value passed to date got a nasty prefix.

I can't reproduce this on fedora core 6, which is the closest Linux
box.  I suspect this is prompt string or PROMPT_COMMAND related, so a
transcript of running this script with `bash -x' would help.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/




Re: Variable passed to system contains garbage characters

2007-12-17 Thread Patrick Nagelschmidt

At 17.12.2007, Chet Ramey wrote:

I can't reproduce this on fedora core 6, which is the closest Linux
box.  I suspect this is prompt string or PROMPT_COMMAND related, so a
transcript of running this script with `bash -x' would help.


No problem:

$ bash -x "./test.sh"
+ alias 'scr=screen -R '
+ '[' -f /etc/bashrc ']'
+ . /etc/bashrc
++ '[' 508 -gt 99 ']'
+++ id -gn
+++ id -un
++ '[' donkey = donkey ']'
++ umask 002
++ '[' '' ']'
++ shopt -q login_shell
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/colorls.sh ']'
++ . /etc/profile.d/colorls.sh
+++ alias 'll=ls -l'
+++ alias 'l.=ls -d .*'
+++ COLORS=/etc/DIR_COLORS
+++ '[' -e /etc/DIR_COLORS.xterm ']'
+++ COLORS=/etc/DIR_COLORS.xterm
+++ '[' -e /home/donkey/.dircolors ']'
+++ '[' -e /home/donkey/.dircolors.xterm ']'
+++ '[' -e /home/donkey/.dir_colors ']'
+++ '[' -e /home/donkey/.dir_colors.xterm ']'
+++ '[' -e /etc/DIR_COLORS.xterm ']'
 dircolors --sh /etc/DIR_COLORS.xterm
+++ eval 
'LS_COLORS='\''no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:'\'';' 
export LS_COLORS
 
LS_COLORS='no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:'

 export LS_COLORS
+++ '[' -z 
'no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:' 
']'

+++ egrep -qi '^COLOR.*none' /etc/DIR_COLORS.xterm
+++ alias 'll=ls -l --color=tty'
+++ alias 'l.=ls -d .* --color=tty'
+++ alias 'ls=ls --color=tty'
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/cvs.sh ']'
++ . /etc/profile.d/cvs.sh
+++ export CVS_RSH=ssh
+++ CVS_RSH=ssh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/glib2.sh ']'
++ . /etc/profile.d/glib2.sh
+++ export G_BROKEN_FILENAMES=1
+++ G_BROKEN_FILENAMES=1
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/krb5-devel.sh ']'
++ . /etc/profile.d/krb5-devel.sh
+++ echo /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/donkey/bin
+++ /bin/grep -q /usr/kerberos/bin
+++ echo /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/donkey/bin
+++ /bin/grep -q /usr/kerberos/sbin
 /usr/bin/id -u
+++ '[' 508 = 0 ']'
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/lang.sh ']'
++ . /etc/profile.d/lang.sh
+++ sourced=0
+++ '[' -n en_US ']'
+++ sourced=1
+++ '[' -n '' ']'
+++ '[' 1 = 1 ']'
+++ '[' -n en_US ']'
+++ export LANG
+++ '[' -n '' ']'
+++ unset LC_ADDRESS
+++ '[' -n '' ']'
+++ unset LC_CTYPE
+++ '[' -n '' ']'
+++ unset LC_COLLATE
+++ '[' -n '' ']'
+++ unset LC_IDENTIFICATION
+++ '[' -n '' ']'
+++ unset LC_MEASUREMENT
+++ '[' -n '' ']'
+++ unset LC_MESSAGES
+++ '[' -n '' ']'
+++ unset LC_MONETARY
+++ '[' -n '' ']'
+++ unset LC_NAME
+++ '[' -n '' ']'
+++ unset LC_NUMERIC
+++ '[' -n '' ']'
+++ unset LC_PAPER
+++ '[' -n '' ']'
+++ unset LC_TELEPHONE
+++ '[' -n '' ']'
+++ unset LC_TIME
+++ '[' -n '' ']'
+++ unset LC_ALL
+++ '[' -n '' ']'
+++ unset LANGUAGE
+++ '[' -n '' ']'
+++ unset LINGUAS
+++ '[' -n '' ']'
+++ unset _XKB_CHARSET
 /sbin/consoletype
+++ consoletype=pty
+++ '[' -n '' ']'
+++ '[' -n '' ']'
+++ '[' -n en_US ']'
+++ case $LANG in
+++ '[' xterm = linux ']'
+++ unset SYSFONTACM SYSFONT
+++ unset sourced
+++ unset langfile
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/less.sh ']'
++ . /etc/profile.d/less.sh
+++ '[' -x /usr/bin/lesspipe.sh ']'
+++ export 'LESSOPEN=|/usr/bin/lesspipe.sh %s'
+++ LESSOPEN='|/usr/bin/lesspipe.sh %s'
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/mc.sh ']'
++ . /etc/profile.d/mc.sh
+++ alias 'mc=. /usr/share/mc/bin/mc-wrapper.sh'
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/vim.sh ']'
++ . /etc/profile.d/vim.sh
+++ '[' -n '3.2.33(1)-release' -o -n '' -o -n '' ']'
+++ '[' -x //usr/bin/id ']'
 //usr/bin/id -u
+++ '[' 508 -le 100 ']'
+++ alias vi
+++ alias vi=vim
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/which-2.sh ']'
++ . /etc/profile.d/which-2.sh
+++ alias 'which=alias

Re: Variable passed to system contains garbage characters

2007-12-17 Thread Andreas Schwab
Patrick Nagelschmidt <[EMAIL PROTECTED]> writes:

> ++ echo '1197919330 - (1197919330 % 86400) - 86400'
> ++ bc -i

This is bogus.  Why are you forcing bc in interactive mode?

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Re: Variable passed to system contains garbage characters

2007-12-17 Thread Bob Proulx
Patrick Nagelschmidt wrote:
> The script below fails on my box with the following output:
> 
> 1197676800
> date: invalid date `1970-01-01 \033[?1034h1197676800 sec'
> 
> So for some reason the value passed to date got a nasty prefix.

I cannot recreate the problem.  However I think your issue is because
you are forcing bc into interactive mode.

> #!/bin/bash
> let "STEP=86400"
> let "CALCTIME=`date +%s`"
> export DAYSTART=`echo "$CALCTIME - ($CALCTIME % $STEP) - $STEP" |bc 
> -i |tail -1`

Remove the -i option from bc and see if that solves your problem.  My
version of bc does not produce escape sequences but it appears that
yours does.  You don't want to run bc in interactive mode here
regardless.

> echo "$DAYSTART"
> export BASHBUG=`date -d "1970-01-01 $DAYSTART sec" +"%Y-%m-%d %T"`
> 
> Fix:
> Yes, please ;)

But I don't think this has anything to do with bash.  It is a bc /
scripting problem.

As a hint I would remove the pipe to bc and simply let bash do the
math here.  Try this instead.

  #!/bin/bash
  let "STEP=86400"
  let "CALCTIME=`date +%s`"
  export DAYSTART=$(($CALCTIME - ($CALCTIME % $STEP) - $STEP))
  echo "$DAYSTART"
  export BASHBUG=`date -d "1970-01-01 $DAYSTART sec" +"%Y-%m-%d %T"`

Also if you have a new enough version of coreutils then date can be
simplified too.

  export BASHBUG=`date -d "1970-01-01 $DAYSTART sec" +"%Y-%m-%d %T"`

Plus +%F is a more compact date string.

  export BASHBUG=`date -d "1970-01-01 $DAYSTART sec" +"%F %T"`

A fully updated script.  It only uses standard features and could use
the start #!/bin/sh okay too.

  #!/bin/bash
  STEP=86400
  CALCTIME=$(date +%s)
  export DAYSTART=$(($CALCTIME - ($CALCTIME % $STEP) - $STEP))
  echo "$DAYSTART"
  export BASHBUG=$(date -d "@$DAYSTART" +"%Y-%m-%d %T")
  echo "$BASHBUG"
  exit 0

Bob




Re: Variable passed to system contains garbage characters

2007-12-17 Thread Chet Ramey
Andreas Schwab wrote:
> Patrick Nagelschmidt <[EMAIL PROTECTED]> writes:
> 
>> ++ echo '1197919330 - (1197919330 % 86400) - 86400'
>> ++ bc -i
> 
> This is bogus.  Why are you forcing bc in interactive mode?

I'm assuming this is the problem, since bc -i uses readline, and the
bogus sequence looks suspiciously like a terminal initialization
sequence.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/




Re: Variable passed to system contains garbage characters

2007-12-17 Thread Patrick Nagelschmidt

At 17.12.2007, Bob Proulx wrote:

Patrick Nagelschmidt wrote:
> The script below fails on my box with the following output:
>
> 1197676800
> date: invalid date `1970-01-01 \033[?1034h1197676800 sec'
>
> So for some reason the value passed to date got a nasty prefix.

I cannot recreate the problem.  However I think your issue is because
you are forcing bc into interactive mode.


Ok, thanks guys, you are both right, the interactive mode was the 
cause for this. how could i ever doubt the purity of the bash :)



Br,
 Patrick 






Re: RFE? |> ?

2007-12-17 Thread Matthew Woehlke

Linda Walsh wrote:

I was wondering about a possible RFE and whether or not
it is "inadvisable" or not.  I'd be surprised if no one had
thought of it -- so maybe there is a problem in doing it.

Just like:
&>word#(preferred syntax)
 and
   >&word
 are semantically equivalent to ">word 2>&1"

Has it been thought to make
   |>word#(preferred form)
 semantically equivalent to "2>&1 | word" ?


I note that ">|" is used to "emphatically overwrite a
pre-existing file when the "-c" option is used to prevent
overwrites.  Why wasn't ">!" used for that?

Also, along the same lines (but less useful, IMO) would be
&>>word   #(append stderr & stdout to word)

Just an oft recurring thought


While we're at it, &>- (close stdout and stderr) would be nice!

--
Matthew
"Briins!" -- Zombies





ESC . on # items

2007-12-17 Thread jidanni
$ echo abc
abc
$ #echo xyz
$
Now do "ESC ." and experience the pain of the buzzer or visual bell
that means one has done something bad. Yes, I know you are against
thinking that one would ever want the last item of something one
commented out, but at least you don't have to chastise them :-( I
personally would give them xyz. What ever you do please don't give them
the bell. Odd that one can ^R them but not ESC . them.




Re: ESC . on # items

2007-12-17 Thread Chet Ramey
[EMAIL PROTECTED] wrote:
> $ echo abc
> abc
> $ #echo xyz
> $
> Now do "ESC ." and experience the pain of the buzzer or visual bell
> that means one has done something bad. Yes, I know you are against
> thinking that one would ever want the last item of something one
> commented out, but at least you don't have to chastise them :-( I
> personally would give them xyz. What ever you do please don't give them
> the bell. Odd that one can ^R them but not ESC . them.

As documented, the history library is used to split the previous
history entry into words, and ESC-. fetches the last word, as if the
!$ expansion had been used.

Since `#' is the history comment character, there's no last word for
the history expansion code to fetch.  The bell signals the expected
lack of output.

Not that odd the ^R, which moves between history entries, behaves one
way, and ESC-. and ESC-#, which history expand the previous entry,
behave another.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/




Re: RFE? |> ?

2007-12-17 Thread Chet Ramey
Linda Walsh wrote:
> I was wondering about a possible RFE and whether or not
> it is "inadvisable" or not.  I'd be surprised if no one had
> thought of it -- so maybe there is a problem in doing it.
> 
> Just like:
> &>word#(preferred syntax)
>  and
>>&word
>  are semantically equivalent to ">word 2>&1"
> 
> Has it been thought to make
>|>word#(preferred form)
>  semantically equivalent to "2>&1 | word" ?

There have been a few proposals for some mechanism combining redirection
and piping in this way, but I haven't really liked any of the suggested
notations.  Note that "|>word" already has a well-defined meaning, and
your proposal isn't backwards-compatible.  (That's a common problem.
The shell syntax is running out of reasonable character combinations.)

zsh uses |&, which is not bad, though ksh uses that to run a coproc.  I
also like the vaguely rc-like [n]| to mean "n>&1 |", but that's a harder
parse.

> I note that ">|" is used to "emphatically overwrite a
> pre-existing file when the "-c" option is used to prevent
> overwrites.  Why wasn't ">!" used for that?

Because >| was existing practice.

> Also, along the same lines (but less useful, IMO) would be
> &>>word   #(append stderr & stdout to word)

That's reasonable.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/




Recursive directory traversal?

2007-12-17 Thread James McMurray

How can I recursively move through a directory tree and call a function in
each folder?
-- 
View this message in context: 
http://www.nabble.com/Recursive-directory-traversal--tp14375793p14375793.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: Recursive directory traversal?

2007-12-17 Thread Bob Proulx
James McMurray wrote:
> How can I recursively move through a directory tree and call a function in
> each folder?

Mike Stroyan recently posted an example doing exactly this:

  http://lists.gnu.org/archive/html/bug-bash/2007-11/msg00080.html

Bob