RFE: a way to echo the arguments with quoting

2014-03-01 Thread Dave Yost
I have an ugly function I wrote for zsh that does this:

Sat 14:17:25 ip2 yost /Users/yost
1 634 Z% echo-quoted xyz \$foo  'a b c ' '\n'
xyz '$foo' 'a b c ' '\n'
Sat 14:17:53 ip2 yost /Users/yost
0 635 Z% 

It would be nice if there were an easy way to do this in bash.

Here is my use case:

echo-command() {
echo-n 1>&2 "[ "
echo-quoted -n 1>&2$@
echo   1>&2 " ]"
}

echodo() {
echo-command $@
eval "$@"
}

1 652 Z% echodo sleep 1 
[ sleep 1 ]
0 653 Z% 

This is a bit of a hack because when I need to use a pipe character, for 
example, I have to quote it, and that gets echoed in a way that’s wrong for 
this purpose.

0 656 Z% echodo echo abc \| sed 's,b,_,'
[ echo abc '|' sed s,b,_, ]
a_c
0 657 Z% 

A builtin that does my ‘echodo’ without having to escape command-line 
metacharacters is what I really want.

Is there such a thing?

typo in bash manual

2014-03-01 Thread Dave Yost
In http://www.gnu.org/software/bash/manual/bashref.html#GNU-Parallel

Where you say
ls *.gz | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
This will recompress all files in the current directory with names ending in 
.gz using bzip2, running one job per CPU (-j+0) in parallel.

it should be
ls *.gz | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
This will recompress all files in the current directory with names ending in 
.bz2 using bzip2, running one job per CPU (-j+0) in parallel.


Also, you should mention what the +0 does.

bash problem with #!

2005-07-26 Thread Dave Yost

Please see
http://Yost.com/computers/compileAndGo

That page describes a #!/bin/bash script called compileAndGo, which 
is used as the program for a #! script.


In other words, a program starting with

  #!/usr/local/bin/compileAndGo

should invoke /usr/local/bin/compileAndGo, and compileAndGo is a 
program starting with


  #!/bin/bash

Invoking a compileAndGo script works correctly in zsh, but not in 
bash, sh, ksh, csh, or tcsh.


(Is this the first time anyone has used a shell script as a #! program?)

Thanks

Dave


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


bash problem with #!, rev 2

2005-07-26 Thread Dave Yost

[added a diagnosis near the end.]

Please see
http://Yost.com/computers/compileAndGo

That page describes a #!/bin/bash script called compileAndGo, which 
is used as the program for a #! script.


In other words, a program starting with

  #!/usr/local/bin/compileAndGo

should invoke /usr/local/bin/compileAndGo, and compileAndGo is a 
program starting with


  #!/bin/bash

Invoking a compileAndGo script works correctly in zsh, but not in 
bash, sh, ksh, csh, or tcsh.


The problem is that bash is executing the compileAndGo script as if 
it were a bash script.


(Is this the first time anyone has used a shell script as a #! program?)

Thanks

Dave


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: bash problem with #!, rev 2

2005-07-27 Thread Dave Yost

Thanks for your learned analysis.
1. I kind of like the way zsh handles it.
2. In any case, I'll use #!/usr/bin/env
   http://Yost.com/computers/compileAndGo
3. I'll change my pages to reflect the change by around noon 15:00 UTC+8.

Thanks again.

Dave


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: eval a=b\ c

2015-05-27 Thread Dave Yost
OK, I can make it to work in bash if I say
  echodo a=b\\ c
but then zsh tries to execute c. Can’t win.

The problem is: how do I write this function so that it can be invoked 
identically in zsh and bash with identical results of setting a variable to a 
value with a space in it?

> On 2015-05-26, at 1:04 AM, Andreas Schwab  wrote:
> 
> d...@yost.com writes:
> 
>>eval$@
> 
> You are expanding a shell parameter unquoted.  Never do that unless you
> know what you are doing.
> 
>  eval "$@"
> 
> Andreas.
> 
> -- 
> Andreas Schwab, SUSE Labs, sch...@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."


On 2015-05-25, at 6:12 PM, Dennis Williamson  
wrote:

> I'm trying to put a command in a variable, but the complex cases always fail! 
> : http://mywiki.wooledge.org/BashFAQ/050
> 
> Eval command and security issues : http://mywiki.wooledge.org/BashFAQ/048
> 
> On Mon, May 25, 2015 at 2:33 PM,   wrote:
> 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/bash/4.3.39/share/locale' 
> -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I../bash-4.3 
> -I../bash-4.3/include -I../bash-4.3/lib   -g -O2
> uname output: Linux s6.millcomputing.com 2.6.32-504.16.2.el6.x86_64 #1 SMP 
> Wed Apr 22 06:48:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-unknown-linux-gnu
> 
> Bash Version: 4.3
> Patch Level: 39
> Release Status: release
> 
> Description:
> 
> # Echo the arguments, then execute them as a command.
> function echodo() {
>   if [[ -n $ZSH_VERSION ]] ; then
> echo "[ ${(q)@} ]"
> eval${(q)@}
>   else
> echo "[ $@ ]"
> eval$@
>   fi
> }
> echodo echo b\ c
> echodo a=b\ c
> echo $a
> 
> The result in zsh is:
>   $ echodo echo b\ c
>   [ echo b\ c ]
>   b c
>   $ echodo a=b\ c
>   [ a=b\ c ]
>   $ echo $a
>   b c
>   $
> 
> Bash gets an error:
>   $ echodo echo b\ c
>   [ echo b c ]
>   b c
>   $ echodo a=b\ c
>   [ a=b c ]
>   bash: c: command not found
>   $ echo $a
> 
>   $
> 
> I can't find a way to implement echodo in bash. Apparently this is because 
> bash is unable to expand a variable with quoting intact, as zsh can do with 
> its (q) expansion flag.
> 
> Bash behaves differently in this case::
> 
>   $ echodo export a=b\ c
>   [ export a=b c ]
>   $ echo $a
>   b
>   $
> 
> 
> Repeat-By:
> 
> 
> 
> Fix:
> 
> 
> 
> 
> -- 
> Visit serverfault.com to get your system administration questions answered.
>