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

后端 未结 8 1767
刺人心
刺人心 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:50

    In bash, $() helps to run a command and capture the output. Passing this to IFS with \n as delimiter helps to convert that to an array.

    IFS='\n' read -r -a txt_files <<< $(find /path/to/dir -name "*.txt")
    

提交回复
热议问题