Bash - Redirection with wildcards

后端 未结 3 1322
春和景丽
春和景丽 2021-01-28 05:19

I\'m testing to do redirection with wildcards. Something like:

./TEST* < ./INPUT* > OUTPUT

Anyone have any recommendations? Thanks.

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 05:28

    There is a program called TEST* that has to get various redirection into into called INPUT*, but the thing is there are many TEST programs and they all have a different number, e.g. TEST678. What I'm trying to do is push all the random INPUT files into all the all TEST programs.

    You can write:

    for program in TEST*            # e.g., program == 'TEST678'
    do
      suffix="${program#TEST}"      # e.g., suffix == '678'
      input="INPUT$suffix"          # e.g., input == 'INPUT678'
      "./$program" < "$input"       # e.g., run './TEST678 < INPUT678'
    done > OUTPUT
    

提交回复
热议问题