Send input to running shell script from bash -


i'm writing test suite app , using bash script check test suite output matches expected output. here section of script:

for filename in test/*.bcs ;     ./bcsc $filename > /dev/null     number=`echo "$filename" | awk -f"[./]" '{print $2}'`     gcc -g -m32 -mstackrealign runtime.c $filename.s -o test/e$number     # run file , diff against expected output     echo "running test file... "$filename     test/e$number > test/e$number.out     if [ $number = "4" ]             # it's trying read line         # pass input file...     fi     diff test/e$number.out test/o$number.out done 

test #4 tests reading input stdin. i'd test script #4, , if pass set of sample inputs.

i realized

test/e4 < test/e4.in > test/e4.out 

where e4.in has sample inputs. there way pass input running script?

if want supply input data directly in script, use here-document:

    test/e$number > test/e$number.out     if [ $number = "4" ];             test/e$number > test/e$number.out <<end_data test input goes here can supply many lines of input want end_data     else         test/e$number > test/e$number.out     fi 

there several variants: if quote delimiter (i.e. <<'end_data'), won't things replace $variable replacement in here-document. if use <<-delimiter, it'll remove leading tab characters each line of input (so can indent input match surrounding code). see "here documents" section in bash man page details.


Comments