current line number in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting current line number in shell script
# 1  
Old 02-26-2010
current line number in shell script

Hi

I am using korn shell is there a built in or ny other way to get the current line number so i can write the current line number to the logfile to aid in debugging like


logmsg $lineno $date

logmsg is a helper function that helps in logging messages to a log file

regards
# 2  
Old 02-26-2010
Use the $LINENO variable
# 3  
Old 02-26-2010
Hi

wow what a elegant and simple solution thanks for letting me know of this

regards
# 4  
Old 02-26-2010
You could just use:
Code:
#!/bin/ksh
export PS4='$0 $LINENO >>'
set -x

This prints every line executed and shows the variables and results
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the line number in shell script

I have one text file 1 2 3 a 5 4 4 3 where i want to print the line number while read line do line_no=`awk '{print NR, $0}'` echo 'In line no $line_no' done <$txt_file If i run the above code, it will print 'In line no 1 1 2 3' It prints the line number with the whole... (3 Replies)
Discussion started by: RJG
3 Replies

2. Shell Programming and Scripting

Detect current shell inside a script

I wish to print my current shell which happens to be bash in my script check.sh more check.sh echo $0 echo `ps -p $$` But instead of printing it prints check.sh i.e the name of the script for both the commands. Can you please suggest how to print the current shell i m on inside the... (2 Replies)
Discussion started by: mohtashims
2 Replies

3. Shell Programming and Scripting

sed script- current and next line

Hi I have been using sed -n -e '/regex/{N;p;}' to print the matching line and the next line. In cases where I have a matching line at the end of the document with no next line, that line is skipped. How do I print that line as well? Thanks. (10 Replies)
Discussion started by: jamie_123
10 Replies

4. Shell Programming and Scripting

How to read from specific line number in shell script?

I have a text file which is having 30000 lines in it. I have to create a xml file for each 10000 lines until all the lines in the text files are written. Also please help how can i get number of lines in the text file in a shell variable? (19 Replies)
Discussion started by: vel4ever
19 Replies

5. Shell Programming and Scripting

Substracting days from current date(K shell script)

Hi, I want to subtract 'n' days from the current timestamp in a k shell script. Is there any inbuilt function to do it or any workaround solution to get the date. And I want the output to be in YYYY:MM:DD HH:MM:SS format. Please help. Thanks in advance. (4 Replies)
Discussion started by: Suryaaravindh
4 Replies

6. Shell Programming and Scripting

Shell script to count number of ~ from each line and compare with next line

Hi, I have created one shell script in which it will count number of "~" tilda charactors from each line of the file.But the problem is that i need to count each line count individually, that means. if line one contains 14 "~"s and line two contains 15 "~"s then it should give an error msg.each... (3 Replies)
Discussion started by: Ganesh Khandare
3 Replies

7. Shell Programming and Scripting

Shell Script to identify the line number containing a particular "string"

Hi, I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file. And then copy 200 lines above that line number to a new file. Can someone provide pointers on how to write this script or what command to be used ? Any... (2 Replies)
Discussion started by: kk2202
2 Replies

8. Shell Programming and Scripting

how do i get current bandwidth usage via shell script?

hello unix-people. can u please tell me how i can get the current bandwidth usage of my machine on shell into variables? thanks a lot (2 Replies)
Discussion started by: scarfake
2 Replies

9. Shell Programming and Scripting

Trigger Shell Script from Current Script

Hello all, I'm new to shell programming and need some help. I would like to set up a step within a shell script to trigger another shell script to run, based on the highest return code generated in the current script. For example, if the highes return code value in the current script is less... (1 Reply)
Discussion started by: mmignot
1 Replies

10. Shell Programming and Scripting

How do i execute script in the current shell

How do i run a shell script or perl script with in the context of a current shell. I know that i can use command source. but we can't pass any arguments to our script if we use source command as it takes only one argement i.e filename Is there any way to run a script in the current shell... (5 Replies)
Discussion started by: Naresh Kumar
5 Replies
Login or Register to Ask a Question