How can I store the “find” command results as an array in Bash

后端 未结 8 1833
刺人心
刺人心 2020-11-22 16:29

I am trying to save the result from find as arrays. Here is my code:

#!/bin/bash

echo \"input : \"
read input

echo \"searching file with this          


        
8条回答
  •  萌比男神i
    2020-11-22 17:10

    For me, this worked fine on cygwin:

    declare -a names=$(echo "("; find   -printf '"%p" '; echo ")")
    for nm in "${names[@]}"
    do
        echo "$nm"
    done
    

    This works with spaces, but not with double quotes (") in the directory names (which aren't allowed in a Windows environment anyway).

    Beware the space in the -printf option.

提交回复
热议问题