Home > Blockchain >  I want to use shell scripting to run my java program for each of my input files
I want to use shell scripting to run my java program for each of my input files

Time:03-24

I have a directory of input files and I want to use a shell script to execute these files onto the console and then create output files in a new output directory.

#!/bin/bash

FILES="inputs/*.txt"
for f in $FILES
do
    basename=${f%.*}
    java main accounts.txt rentalunits.txt
    cat "$f"
    
done >> $basename.out

I tried running this code using

sh testscript

for two text files but it only creates one output file and gets stuck at the first scanner in the java program.

CodePudding user response:

Just guessing

#!/bin/bash

FILES="inputs/*.txt"
for f in $FILES
do
    basename=${f%.*}
    java main accounts.txt rentalunits.txt < "$f" > "$basename.out"
done

Also, no need to specify the interpreter as you have the shebang

chmod  x testscript
./testcript
  • Related