help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Array Expansion


From: J.B.
Subject: [Help-bash] Array Expansion
Date: Sun, 25 Jun 2017 12:25:32 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

Expanding an array for use in a for-loop behaves differently depending on how the array was created. How can I get bash to expand using a different delimiter? I tried `find -print0' after setting IFS= but bash just ignores it (and says so). I then tried `find -exec ls --quoting-style=shell-escape-always', but that didn't work either.

$ !find
find ./path/ -type f -name \*.txt
./path/filename with spaces.txt
./path/good_filename.txt

$ listoffiles=($(find ./path/ -type f -exec ls --quoting-style=shell-escape-always '{}' \;))

$ echo address@hidden
'./path/filename with spaces.txt' './path/good_filename.txt'

$ for file in  address@hidden; do echo $file; done
'./path/filename
with
spaces.txt'
'./path/good_filename.txt'

$ for file in "address@hidden"; do echo $file; done
'./path/filename
with
spaces.txt'
'./path/good_filename.txt'

$ for file in "${listoffiles[*]}"; do echo $file; done
'./path/filename with spaces.txt' './path/good_filename.txt'

$ !unse
unset -v listoffiles

$ listoffiles=(
> './path/filename with spaces.txt'
> './path/good_filename.txt'
> )

$ for file in address@hidden; do echo $file; done
./path/filename
with
spaces.txt
./path/good_filename.txt

$ for file in "address@hidden"; do echo $file; done
./path/filename with spaces.txt
./path/good_filename.txt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]