[英]How can I tell a Linux Script (ash, not bash) is running “sourced”?
[英]In a bash script, how can I tell if the script output is redirected to a file?
我想編寫一個shell腳本,當輸出是終端時將使用彩色輸出,並在重定向到文件時使用正常輸出。 我怎樣才能做到這一點?
很簡單:
if [ -t 1 ]; then
echo "Hello, terminal."
else
echo "Not a terminal."
fi
-t
測試給定的文件描述符(此處為1 = stdout)是否附加到終端。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.