Re: eval a=b\ c
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 Dunno, but I see nothing on that page about using printf -v "%q" or using single quotes inside of doubles... in his first example: # This code is evil and should never be used! fifth() { _fifth_array=$1 eval echo "\"The fifth element is \${$_fifth_array[4]}\"" # DANGER! } a=(zero one two three four five) fifth a --- Had been written: fifth() { printf -v _fifth_array "%q" "$1" eval echo "'The fifth element is ${ echo "${_fifth_array[4]}" }'" } --- Then his arbitrary arg function throws an error: fifth 'x}'; date; -bash: 'The fifth element is ${ echo "${_fifth_array[4]}" }': bad substitution However, if someone takes user input... it needs to be way sterilized -- i.e. if expecting a single char -- only accept a single char. if expecting a number... ${i//[^0-9]/} : i=948392480 Ishtar:law> echo ${i//[^0-9]/} 948392480 i=9'\010'3{92}480 echo ${i//[^0-9]/} 9010392480 --- But I think a difference between greg's thinking and mine is that I tend to write scripts to help me do things on my system. If someone else wants to use my scripts -- and then use them to try to break into their own systemum... *oh well*... ;-)
Re: eval a=b\ c
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.
Re: Check linux 4
On 25 May 2015 17:38, Chet Ramey wrote: > On 5/25/15 9:15 AM, isabella parakiss wrote: > > This is from configure.ac > > > > linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading > > case "`uname -r`" in > > 2.[[456789]]*|3*) AC_DEFINE(PGRP_PIPE) ;; > > esac ;; > > > > It doesn't check for linux 4. > > Two things: > > 1. Is anyone actually using 4.0 in a distribution? all the rolling release distros ? i've been running 4.0 pretty much since it came out. > 2. If you're looking at bash-4.3, why would you have expected a version >from a couple of years ago to check for it? to be fair, that's what the code looks like in git too ... but as long as when 4.4 is released, we don't have the same conversation when linux-5.0 is released ;) > Between configure.ac and BASH_SYS_PGRP_SYNC, I imagine that it will be > covered when 4.0 makes it out to the world. can't we simply delete the uname check ? it's wrong when cross-compiling and redundant with the other macro. -mike signature.asc Description: Digital signature
Re: eval a=b\ c
d...@yost.com 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 You need to put \\ there: echodo () { echo "[ $a ]" eval $@ } Ishtar:law> echodo a=b\\ c [ b\ c ]< echo $a b c Your first BackSlash was removed on the calling command line, that means (as the 'echo' shows, that the BS is no longer there. so you are telling eval to evaluate both expressions a=b & 'c' But if you use \\, one goes away on call, and the other is till there for eval. [ 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 ] Ishtar:law> echo $a b c --- Same ... You are using 2 levels of dequoting, so you need 2 BS's. Make sense? Alternatively, you can pass 1 BS if you quote the initial expression: echodo 'export a=b\ c' [ export a=b\ c ] Ishtar:law> typeset -p a declare -x a="b c" (I used typeset (or declare) -p to also show the "-x" (export) flag was set). Alternatively you could also do it this way: echodo () { printf -v v -- "%q " "$@" echo "$v"; eval $v } Ishtar:law> echodo export a=b\ c export a=b\ c Ishtar:law> typeset -p a declare -x a="b c" You can do what you want in bash, you just have to be clear about what you are telling it (same goes for most any program! ;-))
Re: Check linux 4
Chet Ramey writes: > 1. Is anyone actually using 4.0 in a distribution? Sure: openSUSE Tumbleweed. > 2. If you're looking at bash-4.3, why would you have expected a version >from a couple of years ago to check for it? I would have expected that it checks for Linux 10.0 as well, or anything inbetween or beyond. 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."
Re: eval a=b\ c
On 25/05/15 20:33, d...@yost.com wrote: > if [[ -n $ZSH_VERSION ]] ; then > echo "[ ${(q)@} ]" > eval${(q)@} > else > echo "[ $@ ]" > eval$@ > fi I believe the bash equivalent here would be something along the lines of: quoted=$(printf '%q ' "$@") quoted=${quoted% } echo "[ $quoted ]" eval "$quoted" You mention that bash is "unable to expand a variable with quoting intact", but nor is zsh. Zsh and bash can only quote a variable so that it won't break when used as an argument, but there is no way to retrieve the original quoting once it has been parsed by the shell. Usually if you want to pass around executable bash code you should do it in one already properly-quoted string that gets passed around in a single argument. Quoting the string (as we're having to do as part of "echodo") might be better off as another function. You already have zsh and bash cases, and I've seen some 'clever' shell quoting tricks at http://www.etalabs.net/sh_tricks.html which should work across pretty much every bourne-like shell under the sun.
Re: Check linux 4
On 5/25/15 9:15 AM, isabella parakiss wrote: > This is from configure.ac > > linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading > case "`uname -r`" in > 2.[[456789]]*|3*) AC_DEFINE(PGRP_PIPE) ;; > esac ;; > > It doesn't check for linux 4. Two things: 1. Is anyone actually using 4.0 in a distribution? 2. If you're looking at bash-4.3, why would you have expected a version from a couple of years ago to check for it? Between configure.ac and BASH_SYS_PGRP_SYNC, I imagine that it will be covered when 4.0 makes it out to the world. -- ``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/
eval a=b\ c
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:
Re: Check linux 4
On 25 May 2015 15:15, isabella parakiss wrote: > This is from configure.ac > > linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading > case "`uname -r`" in > 2.[[456789]]*|3*) AC_DEFINE(PGRP_PIPE) ;; > esac ;; > > It doesn't check for linux 4. this isn't strictly a problem because there's already the BASH_SYS_PGRP_SYNC macro that does a compile/run test. probably should delete this uname based code entirely at this point ... -mike signature.asc Description: Digital signature
Check linux 4
This is from configure.ac linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading case "`uname -r`" in 2.[[456789]]*|3*) AC_DEFINE(PGRP_PIPE) ;; esac ;; It doesn't check for linux 4. --- xoxo iza