-3

New to Linux here, sorry for the (easy?) question:

I have a script in Linux called script_run that works fine if I run it once and manually designate filenames. The script reads an input file, interpolates the data, and then saves the interpolated data to an output file. I'd like the output file to have the same name, except with a "_interp" added. I want to automate the script to run for all files in the file folder directory. How do I do this? My attempt is below, and I am running the script in the file folder directory, but it fails to loop. Thank you for your help!

FILEFOLDER=$*

for FILES in $FILEFOLDER
do
script_run "
[--input ${FILES}]
[WriterStd --output tmp_output_${FILES}.txt]"

cat tmp_output_${FILES}.txt >> output_${FILES}_interp.txt
done
zemone
  • 97
  • 7
  • 2
    Possible duplicate of [How to iterate over files in a directory with Bash?](https://stackoverflow.com/q/20796200/608639), [Bash script to execute command on all files in a directory](https://stackoverflow.com/q/10523415/608639), [How to do something to every file in a directory using bash?](https://stackoverflow.com/q/1310422/608639), [for loop over specific files in a directory using Bash](https://stackoverflow.com/q/14823830/608639), etc. – jww Aug 29 '18 at 15:00
  • 1
    Also see [How to use Shellcheck](https://github.com/koalaman/shellcheck), [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](https://askubuntu.com/q/21136) (AskU), [Debugging Bash scripts](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html), etc. – jww Aug 29 '18 at 15:09
  • My apologies, I felt those answers did not address my issue of filepath / directory naming – zemone Aug 30 '18 at 17:44

1 Answers1

0
#!/bin/bash

FILES=`ls *.*`
for FILE in $FILES
do
    script_run "[--input ${FILE}] [WriterStd --output tmp_output_${FILE}.txt]"
    cat tmp_output_${FILE}.txt >> output_${FILE}_interp.txt
done

btw what's with this strange annotation [--input ${FILE}] ? Does your script explicitly requires a format like that?

the.Legend
  • 626
  • 5
  • 13
  • Thanks, that worked. The --input annotation is part of the script_run package, which explicitly requires that formatting. – zemone Aug 30 '18 at 17:43