Re: bash read and field separator
On Fri, Dec 09, 2022 at 10:23:29PM +0700, Max Nikulin wrote:
> find dir dir/ dir// | sed -n l
> dir$
> dir/$
> dir//$
>
> find dir dir/ dir// -printf '%T@/%TY-%Tm-%Td/%TT/%p\0' | sort -zn |
> while IFS=/ read -rd '' _ day time path; do
> printf '%s %s %s\n' "$day" "${time%.*}" "$path";
> done | sed -n l
> 2022-12-09 22:13:14 dir$
> 2022-12-09 22:13:14 dir$
> 2022-12-09 22:13:14 dir//$
>
> Single trailing / disappeared. Using any other character may cause incorrect
> path in the output.
I can't reproduce your result.
unicorn:~$ mkdir tmp/leaf
unicorn:~$ find tmp/leaf tmp/leaf/ tmp/leaf//
tmp/leaf
tmp/leaf/
tmp/leaf//
unicorn:~$ find tmp/leaf tmp/leaf/ tmp/leaf// -printf '%T@/%TY-%Tm-%Td/%TT/%p\0' | while IFS=/ read -rd '' _ day time path; do printf '%s\n' "$path"; done
tmp/leaf
tmp/leaf/
tmp/leaf//
Which version of bash are you using, or is it some other shell?
Reply to: