0

I am new to shell scripting. I tried the below code for first checking whether any XML files exists in the specified directory. If one is found then I need to store the XML files in to the array to process the data. But the below lines are not working. What am I doing wrong? Please suggest the correct approach.

if [ -f ${Input_Path}/ABC/*.XML ] 
then
    arr=(${Input_Path}/ABC/*.XML)
    for i in "${arr[@]}";
        do
            .......
        done
kebs
  • 6,387
  • 4
  • 41
  • 70
siva
  • 5
  • 1
  • 6

1 Answers1

0

You can use as below;

#!/bin/bash
Input_Path=$1
myarray=()

while IFS= read -rd '' files; do 
myarray+=("$files")
#do something;
done < <(find ${Input_Path} -type f -name '*.xml' -print0)

printf '%s\n' "${myarray[@]}"

run as below;

./script <yourInputPath>

ex:

user@user-host:/tmp/1$ ./test.sh /tmp/1
/tmp/1/2.xml
/tmp/1/4.xml
/tmp/1/3.xml
/tmp/1/1.xml
Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24