Re: best way to test for empty dir?

2009-12-15 Thread Antonio Macchi
[ -e "foo" -o -L "foo" -a ! -e "foo" ] it has no sense doing twice the "-e" test $ ln -s nonexistent foo $ [ -e "foo" -o -L "foo" -a ! -e "foo" ] && echo ok || echo ko ok $ [ -e "foo" -o -L "foo" ] && echo ok || echo ko ok as you can see, the first "-e" check imply the second one (aka, if

Re: best way to test for empty dir?

2009-12-11 Thread Antonio Macchi
is_file() { [ -f "$1" ] } is_file /path/to/dir/* || echo empty test is redundant too --- this could be another way to accomplish this empty_dir() { eval test \" $1/* \" == \"" $1/* "\"; } (excluding invisible files...)

Re: best way to test for empty dir?

2009-12-11 Thread Antonio Macchi
is_file() { [ -f "$1" ] && return return 1 } is_file /path/to/dir/* || echo empty you don't need to check more than the first element

Re: IFS handling and read

2009-12-01 Thread Antonio Macchi
Юрий Пухальский wrote: Good day! Theres is a problem with a following code: echo a:b|IFS=: read a b; echo $a this seems work $ echo "a:b" | { IFS=":" read a b; echo $a; } a

Re: operators available in bash versions

2009-11-30 Thread Antonio Macchi
Gerard wrote: I apologize for asking what is probably a dumb question, but where can I find a definitive listing of what features are available in each version of Bash. For example, I only have access to Bash-4 on my system. I need to know if " $(< " also works on Bash < 4. I also have a few que

Re: <( error

2009-11-30 Thread Antonio Macchi
Based on your question, I'm guessing you're in bash 3.2 or earlier, where $ echo $BASH_VERSION 3.2.39(1)-release $ cat /etc/issue Debian GNU/Linux 5.0 \n \l your "hd <(echo -en \\0{0..3}{0..7}{0..7})" is expanded as if you had typed "hd <(echo -en \\) <(echo -en \\0001) <(echo -en \\000

Re: <( error

2009-11-28 Thread Antonio Macchi
Also perhaps indicate what you want to achieve (I don't have an hd command, and didn't find a man page after a quick search) sorry.. i'll be more precise in future... but, if you don't have hd (hexdump) how can you see the content of a, for example, strange file i mean $ ls -l total 0 -rw-r

<( error

2009-11-28 Thread Antonio Macchi
$ hd <(echo -en \\0{0..3}{0..7}{0..7}) it breaks the console.

Re: printf "%q" and $'...'

2009-11-25 Thread Antonio Macchi
The answer is in the part you neglected to read. NULL can be passed to function only "escaped" \0 \x00 but $'\x00' is not like "\x00", because the first is expanded "before", and the second is expanded "after" $ printf $'\x00' +-+-+-+-+-+-+--+ +--+--+ |p|r|i|n|t|f|\0| |\0|\0| +-+-+-+-+-

Re: printf "%q" and $'...'

2009-11-25 Thread Antonio Macchi
When you run read -d $'\x00' what you're really doing is setting up a bunch of C-strings in memory like this: +-+-+-+-+--+- |r|e|a|d|\0| +-+-+-+-+--+- +-+-+--+- |-|d|\0| +-+-+--+- +--+--+- |\0|\0| +--+--+- WOW! but... $ printf one$'\x00'two\\n +-+-+-+-+-+-+--+ |p|r|i|n|t|f|\0|

Re: printf "%q" and $'...'

2009-11-25 Thread Antonio Macchi
$ printf "\x00\n" | cat -A ^@ it works, so why... $ printf $'\x00' | cat -A $ ... not?

Re: printf "%q" and $'...'

2009-11-25 Thread Antonio Macchi
(Note blank line in the output -- one newline from the echo command, and one from the actual content of $myvar.) Using printf -v instead of x=$(printf) means you don't suffer from the trailing-newline-removal that command substitution does. I'm a bit puzzled by the original e-mail, though. I do

Re: printf "%q" and $'...'

2009-11-25 Thread Antonio Macchi
it sounds strange, beacuse $ find . -print0 | while read -d $'\x00'; do touch "$REPLY"; done works fine. but if I try to "output" $'\x00', I can't.

printf "%q" and $'...'

2009-11-24 Thread Antonio Macchi
Hi, I'm using older bash 3.2.39, so please forgiveme if in your newer bash this issue does not arise. 0x00 and 0x0a has no output in printf "%q" $ for i in {0..9} a; do printf "%q\n" "`echo -en \"\x0$i\"`"; done '' $'\001' $'\002' $'\003' $'\004' $'\005' $'\006' $'\a' $'\b' $'\t' '' -

Re: qwerty

2009-11-12 Thread Antonio Macchi
http://www.opengroup.org/onlinepubs/9699919799/utilities/printf.html#tag_20_94 (ouch!) ok! thanks!

Re: qwerty

2009-11-12 Thread Antonio Macchi
I'm on error, I know... but, in your bash-ref guide you don't explain a lot printf and in man printf don't do it too... from man printf - NOTE: your shell may have its own version of printf, which usually supersedes the version described here. Please refer to your s

for i in {1..100000...

2009-11-12 Thread Antonio Macchi
what's the rasonable limit in using this "compact" contruct, after which the for (( i=0; i<1000...; i++ )) became better?

Re: qwerty

2009-11-11 Thread Antonio Macchi
There's nothing to fix. It might help if you provide some markers sorry, and thanks for your patience... in your test patterns so you can see where each argument begins and ends, e.g., $ printf "(%d) {%s}\n" 1 ok - (1) {ok} -bash: printf: -: invalid number (0) {} ... and f

qwerty

2009-11-11 Thread Antonio Macchi
$ printf "%s\n" ok - ok - why that score in the newline? $ printf "%d %s\n" 1 ok - 1 ok -bash: printf: -: invalid number 0 why getting error here, and not in the previous? why "invalid number" ? what is that zero? $ printf "%2s\n" qwerty qwerty strings larger than fixed-wi

read + ^V

2009-11-11 Thread Antonio Macchi
using ^V to pass an ascii character to read, the behavior is incoherent beetween simple read, and read -nx $ read ^V^A $ hd <(echo -n $REPLY) 01|.| 0001 $ read -n1 ^V $ hd <(echo -n $REPLY) 16

[OT] graphic characters set

2009-02-25 Thread Antonio Macchi
this command should starts the graphic character set (to create masks) $ tput smacs but, using aterm or Eterm, it does not work but it works using this form (lieing...) $ TERM=xterm tput smacs does anyone know where is the problem?

Re: {# - strange behavior

2009-02-22 Thread Antonio Macchi
Yes, it's ok. Posix says that printf field widths are specified in number of bytes. I've never red nothing about POSIX, but imho, in the past, "char" and "byte" was synonymous maybe last POSIX definitions are very old...

[OT] mixed dialog boxes

2009-02-21 Thread Antonio Macchi
hi thanks for your helps... I have written some code to create mixed dialog boxes, using a way roughly like object-oriented, i.e. using objects, properties and events. may be it can be useful to someone you can "take a look" using this link: http://www.webalice.it/antonio_macchi/sourcedialog.

Re: {# - strange behavior

2009-02-21 Thread Antonio Macchi
Antonio Macchi wrote: thanks... but parameters expansions and printf builtin works differently about it... same problem with read... LC_CTYPE="en_US.UTF-8" $ read -n1 è $ hexdump -C <(echo -n $REPLY) c3|.| 0

Re: {# - strange behavior

2009-02-21 Thread Antonio Macchi
thanks... but parameters expansions and printf builtin works differently about it... $ locale | grep LC_CTYPE LC_CTYPE="en_US.UTF-8" $ a=eèèèe $ b=e $ echo ${#a} 5 $ echo ${#b} 5 $ printf "*%-10s*" $a *eèèèe * $ printf "*%-10s*" $b *e * is it ok?

Re: {# - strange behavior

2009-02-20 Thread Antonio Macchi
Antonio Macchi wrote: $ a=$'\xd9\xbf' $ echo ${#a} 1 $ a2=${a:0:1} $ echo ${#a2} 1 ops... I mean... $ a2=${a:0:1} $ hexdump -C <(echo $a2) d9 bf 0a |...| 0003 seems bash can't break this two characters...

{# - strange behavior

2009-02-20 Thread Antonio Macchi
$ a=$'\xd9\xbf' $ echo ${#a} 1 $ a2=${a:0:1} $ echo ${#a2} 1 this two characters are "j" and "k" graphical characters in linux terminal/console I need to extract only one... but apparently I can't.

Re: Bash with colors?

2009-02-16 Thread Antonio Macchi
And for the same reason some people hardcode the dot or the comma as thousands separator in their code, ignoring locale settings. "Never seen something different." what's the best? hardcoding, improving efficiency, and putting another brick on the wall of standardization.. ...or i18n/TERM

Re: Bash with colors?

2009-02-15 Thread Antonio Macchi
commands like "ls --color" does not use terminfo capabilities... ...use instead fixed strings (without regards about TERMinal) is this a good (and safe) choice too? IMHO not. Too many assumptions. GNU ls seems to always assume an ANSI terminal, regardless which TERM is set. Or did I miss some

Re: Bash with colors?

2009-02-15 Thread Antonio Macchi
Start at http://bash-hackers.org/wiki/doku.php/scripting/terminalcodes commands like "ls --color" does not use terminfo capabilities... $ hexdump -c <(TERM=xterm ls -d / --color=always) 000 033 [ 0 0 m 033 [ 0 1 ; 3 4 m / 033 [ 010 0 0 m \n 033 [ m

Re: environment

2009-02-13 Thread Antonio Macchi
The environment is designed to be inherited. The subshell even inherits the shell variables. I 'm not sure what causes you trouble here or what it could be incoherent with? i think that $ ( echo $x ) is like $ bash -c 'echo $x' I'm on error... but I can't understand why

environment

2009-02-13 Thread Antonio Macchi
$ declare +x x $ x=one $ ( echo $x; x=two; echo $x ) one two subshell inherits "x"? is this behavior coherent?

is this coherent?

2009-02-12 Thread Antonio Macchi
$ a=ok $ b=a $ echo ${!b-a} ok $ unset b $ echo ${!b-a} a imho, the last command should expand to "ok" too

Re: read + SIGWINCH - strange error

2008-11-03 Thread Antonio Macchi
trap trapfunc SIGWINCH trapfunc () { for i in {1..1000}; do tput cup 0 0 echo OK done } I have used one thousand echoes only to assure error raising every time. But you can use one hundred instead, and you will see the error raise more rarely Probably error raise (very very rare

read + SIGWINCH - strange error

2008-11-01 Thread Antonio Macchi
If I run this script in xterm, and I maximize (not resize) the window, I'll get (nearly always) a very strange error... something like ./test: line 17: wait_for: No record of process 22659 but if I use 'read' without timing or with a very long time ( -t10 ) the error does not raise. ---

variable scope

2008-10-24 Thread Antonio Macchi
$ a=OUTSIDE $ f1 () { local a=INSIDE; f2; } $ f2 () { echo "before: $a"; unset a; echo "after: $a"; } $ f3 () { local a=INSIDE; echo "before: $a"; unset a; echo "after: $a"; } $ f1 before: INSIDE after: OUTSIDE $ f3 before: INSIDE after: I

tables - $'\x7f' does not loaded properly

2008-10-18 Thread Antonio Macchi
$ a=( $'\x7e' $'\x7f' $'\x80' ) $ hexdump -C <(echo -n [EMAIL PROTECTED] ) 7e 20 01 7f 20 80 |~ .. .| 0006 bash puts two characters (\x01 and \x7f) instead of only one \x7f but... $ a[1]=$'\x7f' $ hexdump -C <(echo -n [EMAIL PROTECTED] ) 0

is it a bug? (little script)

2008-10-05 Thread Antonio Macchi
#!/bin/bash -e trap "rm test_fifo" 0 mkfifo test_fifo ls / > test_fifo & exec 9<&0 while read dirname do echo $dirname # if I wait, exits!!! read -t 2 -p "press enter..." 0<&9 done < test_fifo exec 9<&- exit 0

patch for bash-3.2 to compile under Debian GNU/Linux 4.0 with DietLibc

2008-09-04 Thread Antonio Gallo
Here you are: mercurius:/usr/src/BadPenguin# cat bash-3.2-dietlibc.unified-patch --- build/bash-3.2/lib/sh/winsize.c.orig2006-07-28 05:57:45.0 +0200 +++ build/bash-3.2/lib/sh/winsize.c 2008-09-03 14:56:46.0 +0200 @@ -43,6 +43,11 @@ #include +/* Antonio Gallo

eval, apparently inconsistent behavior

2008-06-06 Thread antonio
#!/bin/bash a=( 1 2 3 ) b=( 4 5 6 ) x=a eval b=( [EMAIL PROTECTED] ) echo [EMAIL PROTECTED] #output: #1 2 3 x=b eval $x=( [EMAIL PROTECTED] ) #output: #./tst: line 15: syntax error near unexpected token `(' #./tst: line 15: `eval $x=( [EMAIL PROTECTED] ) '

wish list addition

2008-06-04 Thread antonio
read -t0 actually does nothing may be, could be used for -flushing pre-entered-key-buffer- while true do read -s -n1 -t0 x test $x && break echo "loop" done

shopt, shopt -o (set -o) manage the same flag (interactive_comments)

2008-04-25 Thread antonio
Description: it's not a bug, but a strange behavior the flag interactive_comments is accessible from both shopt and shopt -o shopt | grep interactive_comments shopt -o | grep interactive_comments in your documentation (bashref), shopt -o (set -o) does not have this flag... thanks for y