Kimi
Kimi

Reputation: 324

Echo the line number of the code in a log file

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

Answers (1)

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

Related Questions