[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: non working code .. loop ends after one
From: |
alex xmb ratchev |
Subject: |
Re: non working code .. loop ends after one |
Date: |
Thu, 2 Mar 2023 00:40:10 +0100 |
On Thu, Mar 2, 2023, 12:20 AM Greg Wooledge <greg@wooledge.org> wrote:
> On Thu, Mar 02, 2023 at 12:07:55AM +0100, alex xmb ratchev wrote:
> > i tried make \0 or \n ( or other accessable )
> > the bash read -d way is '' for 0 and <real n> for n
> >
> > bash read -d sep 'one_char( or more i dunno )'
> > in awk it doesnt matter
>
> I'm not 100% sure what you're saying, so I'll just make this clear:
>
> read's -d option only allows a one-character option argument. That
> character will be used as the LINE delimiter, which tells read when
> to stop reading.
>
> If the option argument is the empty string (-d '' or -d ""), then
> the NUL byte is used as the line delimiter.
>
> This is most likely a side effect of bash's internal code just doing
> something like 'delimiter = argument[0];' which happens to retrieve
> a NUL byte when argument is an empty string, due to how C strings are
> stored internally.
>
> Regardless of whether this was an accident originally, Chet has blessed
> it, and it's officially a supported feature now.
>
> To demonstrate, here is a loop that reads a NUL-delimited list of
> pathnames from find:
>
> while IFS= read -r -d '' pathname; do
> ...
> done < <(find . -type f -print0)
>
> Each read command terminates when it reads a NUL byte, and all of the
> bytes read before that go into the "pathname" variable, with no mangling
> (because of the -r option, and because IFS is empty).
>
> There is no need to use \0 anywhere in this part of the code. (Unless
> you're using a POSIX find command which lacks -print0, in which case
> you might use -exec printf '%s\0' {} + as a workaround.)
>
nah eh i dont posix or gnu i better
:¶
my thoughts about that
1. there is variable separator per entry , line , \0
1.5 its a general purpose script
2 i look to code , generally , full featured code , means user functionality
so
2.1 need unioning commons
2.2 sep \n \0 ( or other s )
2.3 no need awk but just read , less product , .. just code for bash s read
2.4 map user string to actual byte ( here is user , user doesnt enter \\n ,
it can , read value , .. anyway outta users \0 or \n or \1 input is read -d
compatible string to make
3 declare resolves details , no eval
root@localhost:~# v=\\1\\2 ; declare -a "r=( $'$v' )" ; declare -p r
+ v='\1\2'
+ declare -a 'r=( $'\''\1\2'\'' )'
+ declare -p r
declare -a r=([0]=$'\001\002')
i use declare -a as expander
may test without -a .. got new knows now
>
- Re: non working code .. loop ends after one, (continued)
- Re: non working code .. loop ends after one, Greg Wooledge, 2023/03/01
- Re: non working code .. loop ends after one, Lawrence Velázquez, 2023/03/01
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/01
- Re: non working code .. loop ends after one, Lawrence Velázquez, 2023/03/01
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/01
- Re: non working code .. loop ends after one, Andreas Kusalananda Kähäri, 2023/03/02
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/02
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/02
- Re: non working code .. loop ends after one,
alex xmb ratchev <=
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/01
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/01
- Re: non working code .. loop ends after one, Kerin Millar, 2023/03/01
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/02
- Re: non working code .. loop ends after one, Kerin Millar, 2023/03/02
- Re: non working code .. loop ends after one, Greg Wooledge, 2023/03/02
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/03
- Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/03
Re: non working code .. loop ends after one, alex xmb ratchev, 2023/03/01
Re: non working code .. loop ends after one, Chet Ramey, 2023/03/01