$LINENO no show


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting $LINENO no show
# 1  
Old 08-12-2018
$LINENO no show

$LINENO is bash "system" variable but I cannot get any output trying to use it.


Am I missing something fundamental?



Here is the code snippet



Code:
13)
 247                echo "TEMPLATE Option 13"
 248
 249 # *** BEGIN DEBUG BLOCK ***
 250 last_cmd_arg=$_  # Save it.
 251
 252 echo "At line number $LINENO, variable \"v1\" = $v1"
 253 echo "Last command argument processed = $last_cmd_arg"
 254 # *** END DEBUG BLOCK ***
 255
 256 pause



And here is the output in terminal



Code:
TEMPLATE Option 13
At line number , variable "v1" = 
Last command argument processed = 
Press [Enter] key to continue...

# 2  
Old 08-13-2018
We have no idea what you are missing. But, there are lots of things we are missing...

  1. What operating system are you using?
  2. What shell are you using?
  3. What is the first line of the script you are running?
  4. What command did you use to invoke the script you are running?
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 08-13-2018
Are you sure, that the code being executed is inside a bash function? From my understanding of the bash man page, LINENO is not defined outside of functions.
# 4  
Old 08-13-2018
From here: Bash Reference Manual: Bash Variables
Quote:
LINENO

The line number in the script or shell function currently executing.
Example script

Code:
#!/bin/bash
echo "arg count = $#"
while [ $# -gt 0 ]
do
    echo "$1 on $LINENO "
    shift
done

exit

output:
Code:
$ ./t.shl 1 2 3
arg count = 3
1 on 5
2 on 5
3 on 5

So, I'm confused.
According to the maintainers of bash and my Cygwin version of bash, the LINENO variable always exists. So, until Annacreek can tell us the information Don Cragun asked, we cannot know what shell is being used. I would guess the shell is not bash, if in fact the problem line of code actually gets executed when the script runs.
# 5  
Old 08-13-2018
You are right! LINENO also works well outside a function.

As for finding out whether or not you are running bash, there are several ways. First of all, you are running the script, so I would say you know what you are using. There is no magic in this.

Aside from this, you could output the variable BASH_VERSION (which would be empty, unless someone malevolently sets it explicitly). You can also trigger a syntax error in the script; if it is bash, the error message will contain the word "bash".
# 6  
Old 08-13-2018
This isn't just bash... It was in ksh before 1988, and the latest POSIX standard says the following about the LINENO variable:
Quote:
Set by the shell to a decimal number representing the current sequential line number (numbered starting with 1) within a script or function before it executes each command. If the user unsets or resets LINENO, the variable may lose its special meaning for the life of the shell. If the shell is not currently executing a script or function, the value of LINENO is unspecified. ...
So, I guess we should also ask for the output from the command:
Code:
grep LINENO script_pathname

hoping to verify that the script doesn't assign any value to LINENO and doesn't use unset with LINENO as an operand.
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 08-13-2018
'$LINENO is bash "system" variable but I cannot get any output trying to use it."


OK, I did not say "I am using bash ".

Yes, being a geenie I thought
# denotes comments, apparently not.


So I moved
#!/bin/bash back as first line in file



Here is a code snippet :



Code:
czechlist_DEBUG(){
  64 echo "czechlist_DEBUG "
  65 echo "Passed parameter #1 is $1"
  66 echo "Passed parameter #2 is $2"
  67 echo "Passed parameter #3 is $3"
  68 echo "Passed parameter #4 is $4"
  69
   70 echo "arg count = $#"
initialize while "count" 

   71 while [ $# -gt 0 ]
  72 do
  73     echo "$1 on $LINENO " 

 echoes "first" parameter "found" , so the construct 

is 

      while 

      do 

     ...
     done 

??

 
 
  74     shift
  75 done
  76 echo " DONE line output "
  77
  78 pause


And here is an output , getting there:



Code:
czechlist_DEBUG 
Passed parameter #1 is DEBUG USB 
Passed parameter #2 is lsusb
Passed parameter #3 is test par 2
Passed parameter #4 is test par 3
arg count = 4
DEBUG USB  on 73 
lsusb on 73 
test par 2 on 73 
test par 3 on 73 
 DONE line output 
Press [Enter] key to continue...


Last edited by annacreek; 08-13-2018 at 10:25 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Show help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Display the contents of all files ending in a number to the screen 2. Relevant commands, code, scripts,... (2 Replies)
Discussion started by: marcincan
2 Replies

2. Post Here to Contact Site Administrators and Moderators

Show all my Posts?

Hello, Is there a way to display all of the posts I have authored? Many thanks in advance. (1 Reply)
Discussion started by: dlundwall
1 Replies

3. Shell Programming and Scripting

How to show the type of my terminal?

How to show the type of my terminal? Thanks in advance! (1 Reply)
Discussion started by: Henryyy
1 Replies

4. Shell Programming and Scripting

Display LineNo Incase Total Number Of Delimiter Does matches in a given variable

I have many files .dat extension. requirement is to display line no if no of delimiter does not matches in a given variable lets say File: REF_BETOS.dat HCPCS_OR_CPT_CODE~BETOS_CODE~TERMINATION_DATE 0001F~Z2~ 0003T~I4~B20061231 0005F~Z2~~~ 0008T~P8~B20061231... (1 Reply)
Discussion started by: ainuddin
1 Replies

5. UNIX for Dummies Questions & Answers

ls how to not show date

Hello, I'm using ls -laR to print out a list of file and folders. I want to print only the permission, file size and file name. Also, excluding the '.' and '..'. result from ls -laR: total 6 drwxr-xr-x 8 user staff 512 Nov 28 16:17 . drwxr-x--- 16 user staff 1024... (3 Replies)
Discussion started by: minifish
3 Replies

6. UNIX for Dummies Questions & Answers

Show path name

Hello I'm new to this forum. So please spare me! I'm using SCO UnixWare 7.1.4 and created a few accounts. So far so good. When I login I see: $. But here I want to see (for example), /home 25$ So I want to see the pathname where I am without each time typing pwd (2 Replies)
Discussion started by: p.vvugt
2 Replies

7. UNIX Desktop Questions & Answers

Show us your Desktop

I don't see any threads like this and I know that a bunch of people have really cool desktops, so I`ll start. rules 1 no images in your post,attachments only 2 no default desktops, tha would be very much a waste (2 Replies)
Discussion started by: Genral
2 Replies
Login or Register to Ask a Question