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

后端 未结 8 1856
刺人心
刺人心 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条回答
  •  鱼传尺愫
    2020-11-22 16:58

    You could do like this:

    #!/bin/bash
    echo "input : "
    read input
    
    echo "searching file with this pattern '${input}' under present directory"
    array=(`find . -name '*'${input}'*'`)
    
    for i in "${array[@]}"
    do :
        echo $i
    done
    

提交回复
热议问题