[英]How a function should exit when it called with here-document from shell script?
[英]From shell script can we invoke function from here document
我想編寫一個shell腳本,該腳本應從此處的文檔中調用一個函數,如下所示:
#!/bin/bash
funexit
funexit ()
{
exit 1
}
cat <<:EOD:
funexit
:EOD:
請給我一個好的解決方案!
如果我對您的理解正確,那么您需要這樣,
funexit()
{
echo "calling funexit"
exit 1
}
cat <<:EOD:
$(funexit)
:EOD:
你是這個意思嗎
#!/bin/bash
funexit() # Declare function
{
echo $1 # echo parameter
cat # cat STDIN
exit 1 # exit (badly)
}
funexit 3 <<EOD # call function with parameter 3
hello # pass "hello" to its STDIN
EOD
輸出:
./go
3
hello
~: echo $? # Check exit status is 1
1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.