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.
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.
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".
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:
'$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..
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
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)
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)
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)
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)