Redirect standard input dynamically in a bash script

前端 未结 7 813
忘了有多久
忘了有多久 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

    (
        if [ ...some condition here... ]; then
            exec <$fileName
        fi
        exec ./myscript
    )
    

    In a subshell, conditionally redirect stdin and exec the script.

提交回复
热议问题