प्रिंटफ़ का उपयोग करें। मुझे चीजें रंग कोड भी पसंद है। :)
यहाँ प्रस्तावना मैं सेटअप करने के लिए मेरी स्क्रिप्ट रंग और कुछ printf बयान में उपयोग है ...
#!/bin/bash
# checkload.sh - script to check logs for errors.
#
# Created by Ryan Bray, [email protected]
set -e
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset
और फिर मैं इस तरह बयान है कि उत्पादन में रंगों का उपयोग किया है:
printf "Checking for descrepancies in $LOAD_DATE$ADD_COMP\n"
DELTAS=$(awk 'BEGIN { FS = "\"" } {print $24,$26,$28}' $COMP_FILE)
if [[ "$DELTAS" == *[1-9]* ]]; then
printf "%74s[${txtred}FAIL${txtrst}]\n"
printf "$COMP_FILE contains descrepancies.\n"
exit 1
else
printf "%74s[${txtgrn}PASS${txtrst}]\n"
fi
उम्मीद है कि इससे मदद मिलती है!
-Ryan
धन्यवाद, मैं उस फ़ाइल को देखा और कार्रवाई का उपयोग है: कार्रवाई $/path/to/prog आर्ग 'ए ... करना "। ;) धन्यवाद! – Neuquino
मेरे लिनक्स में यह नहीं है (xandros, एक डेबियन संस्करण, eeePC पर)। लेकिन /etc/init.d/* में एक नज़र डालने के कारण, फाइलें उसी तरह से '/ lib/lsb/init-functions' का उपयोग करती हैं, जो इसे परिभाषित करती है, जैसे log_begin_msg, log_progress_msg, log_warning_msg, log_failure_msg और log_end_msg। उनमें से एक संदर्भ '/ etc/init.d/functions' भी संदर्भित करता है, लेकिन केवल अगर सिस्टम redhat है। – 13ren