Reputation: 324
In my script I am using echo and directing the text to a log file like below
echo "`date +"%d%m%Y%H%M%S"` The script is running.. " >> $log_File
How do I print the line number of the echo into the logfile ?
currently in the log file :
01032012141215 The script is running..
into the log file i want this to come as:
01032012141215 100 The script is running..
where 100 is the line number of the echo in the script
Upvotes: 1
Views: 2035
Reputation: 20238
You'll find the line number of the current command in the variable $LINENO
echo "`date +"%d%m%Y%H%M%S"` $LINENO The script is running.. " >> $log_File
I'm not sure that this is a POSIX requirement, but at least most modern shells should provide this variable (bash
sure does)
Upvotes: 4