Bash conditional piping

后端 未结 3 1631
野趣味
野趣味 2021-01-13 03:13

How can I pipe an output of a command just in case it returns true?

function open
{
    TEMPFILE=$(mktemp -u)
    if ! gpg2 --quiet --decrypt --batch --passp         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 03:38

    The following code should conditionally pipe the result if the file opens successfully:

       result=open "$@" "$PASSWORD"
        if [ $? -gt 0 ]; then
          exit 1
        fi
        echo "$result" | 
    

提交回复
热议问题