Reputation: 31
I have a directory of files and I want to build an array of them and double quote them
file1.json file2.json
if I declare my array and do a directory listing:
declare -a array=("$(ls)")
echo ${array[@]}
I get
file1.json file2.json
how do I make the array so that when I output it - it is
"file1.json" "file2.json"
Upvotes: 0
Views: 165
Reputation: 183446
I think your best bet is to use printf
to print each one with double-quotes:
array=(*)
printf '"%s" ' "${array[@]}"
Upvotes: 2