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

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

    The following appears to work for both Bash and Z Shell on macOS.

    #! /bin/sh
    
    IFS=$'\n'
    paths=($(find . -name "foo"))
    unset IFS
    
    printf "%s\n" "${paths[@]}"
    

提交回复
热议问题