How to read a file line by line and store it in a variable to execute a program ?

Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files.

all my parameters files are in the same directory, so pick them up with

ls *.para >>dir

after that I have a dir file like that:

param1.para
param2.para
etc...

I want to run my program prgrm on all parameters file like this:

prgrm param1.para -option XX
prgrm param2.para -option XX

I saw some scripts using awk but the variable 'var' that store the name of the parameter file seem to doesn't exist out of awk. :frowning:

I also tried:

var="*.para"
echo $var |cut -f1 | read str
echo $str

I have all filenames in 'var' but the spliting with cut apparently doesn't work.

do you have easy way to try ?

thanks very much for your help :slight_smile:

---------- Post updated at 09:16 PM ---------- Previous update was at 07:52 PM ----------

ok, I found a way to solve it:

var=*.para

arr=$(echo $var | tr " " "\n")

for x in $arr
do
    prgrm $x
done

:cool:

You can simplify this a bit:

for x in *.para
do
    prgrm $x
done

thanks! It's much more simple like that !

I feel stupid ! lol :wall: