Redirect standard input dynamically in a bash script

前端 未结 7 800
忘了有多久
忘了有多久 2020-12-13 13:56

I was trying to do this to decide whether to redirect stdin to a file or not:

[ ...some condition here... ] && input=$fileName || input=\"&0\"
./         


        
7条回答
  •  攒了一身酷
    2020-12-13 14:43

    Standard input can also be represented by the special device file /dev/stdin, so using that as a filename will work.

    file="/dev/stdin"
    ./myscript < "$file"
    

提交回复
热议问题