arraysshell

Read txt file into an array in shell script


My configs.txt file is in the format

example1
example2
example3

I would like to read a text file configs.txt into an array and then loop through the array to perform a tar command to create a separate tarfile for each entry like example1.gz etc.


Solution

  • Not sure why you need an array

    while read p; do
      echo "$p";
      # tar here
    done < configs.txt 
    

    for p in $(cat configs.txt); do 
      echo "$p";
      # tar here
    done