#251874 - 16/03/2005 19:43
bizarre shell problem
|
member
Registered: 30/04/2003
Posts: 136
Loc: United Kingdom
|
I have a script that includes the following line:-
[ ${@:0-2:1} = '.' ] || echo
but after displaying the text I get
Segmentation fault
If I run the same code on the command line I don't get the error.
If I change the substr code in the script to
${@:0-2}
it's OK - no error, but of course isn't doing what I want. So what can be the problem that causes the error only when in a shell script, but not otherwise?
Come to think of it, what's a segmentation fault?
|
Top
|
|
|
|
#251875 - 16/03/2005 21:08
Re: bizarre shell problem
[Re: ukengb]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14496
Loc: Canada
|
Quote: Come to think of it, what's a segmentation fault?
Bad pointer. You have found a bug in whatever shell you're using. Report it, or it may never get fixed.
Cheers
|
Top
|
|
|
|
#251876 - 16/03/2005 21:13
Re: bizarre shell problem
[Re: ukengb]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14496
Loc: Canada
|
What shell is that for, anyway? Bash doesn't like it as-is. But bash does accept this version:
[ ! ! "${@:2:1}" = "." ] || echo
Cheers
|
Top
|
|
|
|
#251877 - 16/03/2005 22:22
Re: bizarre shell problem
[Re: mlord]
|
carpal tunnel
Registered: 20/12/1999
Posts: 31600
Loc: Seattle, WA
|
Quote: You have found a bug in whatever shell you're using. Report it, or it may never get fixed.
Isn't he talking about Bash in the empeg developer build? So who does he report it to?
|
Top
|
|
|
|
#251878 - 16/03/2005 23:14
Re: bizarre shell problem
[Re: tfabris]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14496
Loc: Canada
|
Quote: Isn't he talking about Bash in the empeg developer build? So who does he report it to?
He didn't say which shell, or platform.
But if it is the player build, then.. no point in reporting it, unless he can also get it to do it on a more modern machine!
Cheers
|
Top
|
|
|
|
#251879 - 17/03/2005 09:50
Re: bizarre shell problem
[Re: mlord]
|
member
Registered: 30/04/2003
Posts: 136
Loc: United Kingdom
|
Quote:
Quote: Isn't he talking about Bash in the empeg developer build? So who does he report it to?
He didn't say which shell, or platform.
But if it is the player build, then.. no point in reporting it, unless he can also get it to do it on a more modern machine!
'He' didn't indicate where this problem was occurring - sorry. I was convinced I had stated this was a script running on the empeg. Anyway, that's where it is and of course it's bash.
The modified code that Mark (Lord) posted probably does work, but it's not what I need. I want to check that the penultimate char is a period, but Mark's code checks the second char. The reason I use '0-1' is that I have found in the past that bash will not accept a negative value when you want to represent that no. of chars from the end of the string, BUT if you use that calculation it does work and indeed that appeared to be the case on the empeg. But as I then discovered, it works when you use the code on the command line, but causes this error when used in a script.
On my RedHat machine I have used these constructs without any problem (once I worked around the negative value problem), so it must be to do with the empeg's bash.
From what you all say it would appear that there's no way around this so I just have to modufy the code and my requirements to work around it. Would that be a fair assessment?
|
Top
|
|
|
|
#251880 - 17/03/2005 12:52
Re: bizarre shell problem
[Re: ukengb]
|
carpal tunnel
Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
|
ISTR that if the first line of your shell is "#!/bin/sh" then bash falls back to some sort of Bourne pseudo-compatibility. If you've got that in there, then try changing it to "#!/bin/bash".
This is just a guess, though.
_________________________
Bitt Faulk
|
Top
|
|
|
|
#251881 - 17/03/2005 13:29
Re: bizarre shell problem
[Re: ukengb]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14496
Loc: Canada
|
I take it you want code to detect the final character of the final arg, and tell whether it was a period or not? Code:
#!/bin/bash all="$@" if [ "${all##*.}" = "" ]; then echo "ended with a dot" else echo "did not end with a dot" fi
|
Top
|
|
|
|
#251882 - 17/03/2005 13:57
Re: bizarre shell problem
[Re: mlord]
|
carpal tunnel
Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
|
He states quite clearly: Quote: I want to check that the penultimate char is a period
_________________________
Bitt Faulk
|
Top
|
|
|
|
#251883 - 17/03/2005 14:41
Re: bizarre shell problem
[Re: wfaulk]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14496
Loc: Canada
|
Quote: He states quite clearly:
Quote: I want to check that the penultimate char is a period
Oh.. dictionary out.. second last character.
Okay, so what he was doing originally should work, so long as his script ensures there are always at least two characters in the string.
Code:
junk=" $@"
[ "${junk:0-2:1}" = "." ] || echo no
Edited by mlord (17/03/2005 14:45)
|
Top
|
|
|
|
#251884 - 17/03/2005 15:16
Re: bizarre shell problem
[Re: mlord]
|
carpal tunnel
Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
|
Hmm. I wonder if that's the problem -- that his test case had less than two characters. Reading past the end of an array would be a common cause for a seg fault and I can believe that there was a version of bash that failed to check for the front end of the array. Seems unlikely, but possible, especially if there was a different bug that failed to put the right thing in the variable being checked.
_________________________
Bitt Faulk
|
Top
|
|
|
|
#251885 - 17/03/2005 17:18
Re: bizarre shell problem
[Re: wfaulk]
|
member
Registered: 30/04/2003
Posts: 136
Loc: United Kingdom
|
Quote: Hmm. I wonder if that's the problem -- that his test case had less than two characters.
No, the test string was about 20 chars so no problem there. Actually I'm not sure if that would be a problem anyway, but in any case not applicable here.
I think the important point here is that the code I used only fails when used in a script, whereas there is NO error when used directly on the command line (nor on my RedHat machine in any circumstances). This is the puzzle, that there is a totally different result when using these 2 methods.
As I said, I'm resigned to figuring a 'get around' as I doubt the empeg bash will get upgraded, but thanks for the support anyway.
|
Top
|
|
|
|
#251886 - 17/03/2005 22:27
Re: bizarre shell problem
[Re: ukengb]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14496
Loc: Canada
|
The last version I posted here runs correctly from a script on my empeg player.
Cheers
|
Top
|
|
|
|
#251887 - 18/03/2005 06:27
Re: bizarre shell problem
[Re: mlord]
|
member
Registered: 30/04/2003
Posts: 136
Loc: United Kingdom
|
OK, I've already re-written my script so that the error doesn't occur, but in the interests of our quest for knowledge and truth, I've doen some more checking:-)
My original line was
[ "${@:0-2:1}" = "." ] || echo
and this causes the seg. fault - always. But if I replace this with:-
anyvarname="$@" [ "${anyvarname:0-2:1}" = "." ] || echo
there is no error. IOW the problem only relates to when $@ is used and seems to confirm the existence of a bash internal bug.
It's no longer a problem for me, but interesting to know what not to do in the future.
|
Top
|
|
|
|
#251888 - 18/03/2005 11:11
Re: bizarre shell problem
[Re: mlord]
|
member
Registered: 30/04/2003
Posts: 136
Loc: United Kingdom
|
A quick question for Mark.
Hijack seems to eliminate multiple spacing from text strings before displaying them in a popup, am I right about this, or is there some other reason why my double spaces are not appearing in the displayed popup message?
|
Top
|
|
|
|
#251889 - 18/03/2005 12:23
Re: bizarre shell problem
[Re: ukengb]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14496
Loc: Canada
|
Quote:
Hijack seems to eliminate multiple spacing from text strings before displaying them in a popup ..?
Nope. Spaces are displayed as three columns of blank pixels each.
Try this, to help understand what is probably confusing you:
Code:
ftp to your player, and then do:
site popup 5 testing 123
site popup 5 "testing 123"
cheers
Edited by mlord (18/03/2005 12:24)
|
Top
|
|
|
|
#251890 - 18/03/2005 12:26
Re: bizarre shell problem
[Re: ukengb]
|
carpal tunnel
Registered: 29/08/2000
Posts: 14496
Loc: Canada
|
Quote:
[ "${@:0-2:1}" = "." ] || echo
and this causes the seg. fault - always. But if I replace this with:-
anyvarname="$@"
[ "${anyvarname:0-2:1}" = "." ] || echo
there is no error
Actually, I was suprised that "${@ ... ]" works at all!
I suppose in the version of bash on the player, the coders may not have anticipated that anyone would even try it, since $@ means something quite different from "$@" or $*.
Cheers
|
Top
|
|
|
|
|
|