All of lore.kernel.org
 help / color / mirror / Atom feed
* ash and String Manipulation
@ 2003-01-03 21:24 Neil Holmes
  2003-01-04  9:50 ` jb1
  0 siblings, 1 reply; 10+ messages in thread
From: Neil Holmes @ 2003-01-03 21:24 UTC (permalink / raw)
  To: Linux 8086

Not sure if there is anyone out there in elks-land that can make some
suggestions here ?

As you know EDE has been developed using shell scripts. Ash is the shell
that we are working with. I had little experience of ash prior to this
exercise. I always understood ash to be a stripped down shell but have
generally found a way around any limitations that I hit. I am scratching my
head a little at the moment though on string manipulation and not being able
to find anything substantial on the web or in the news groups, I thought I
would post a question here. It may save me some time if somebody has some
experience.

Here is a segment of a test script from my EDE Package work :-

string="advent,Text Adventure Game,advent.tar"
a=`expr index "$string" ,`
title=${string:0:$a-1}
trimx=${string#$title}
trim1=${trimx#,}
a=`expr index "$trim1" ,`
desc=${trim1:0:$a-1}
trimx=${trim1#$desc}
tarfile=${trimx#,}
echo "${title}    ${desc}     ${tarfile}"

Run this with bash on Linux and the output is fine. The split up string from
line 1.

Run exactly the same script with ash (on Linux is fine) with and you get :-

strgcut: 3: Syntax error: Bad substitution

It would seem that, as a cut down shell, string manipulation is not a strong
point in ash. What I am struggling to find is a way to code around this. The
"expr index" command does work but I don't seem to be able to find enough
tools in ash to get me where I would like to be. I believe in some shells
there is an "expr substr" but not here.

Has anyone any ideas ?

Thanks

Neil






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ash and String Manipulation
  2003-01-03 21:24 ash and String Manipulation Neil Holmes
@ 2003-01-04  9:50 ` jb1
  2003-01-06 11:12   ` Neil Holmes
  0 siblings, 1 reply; 10+ messages in thread
From: jb1 @ 2003-01-04  9:50 UTC (permalink / raw)
  To: Neil Holmes; +Cc: Linux 8086

On Fri, 3 Jan 2003, Neil Holmes wrote:

> Not sure if there is anyone out there in elks-land that can make some
> suggestions here ?
	...
> Here is a segment of a test script from my EDE Package work :-
> 
> string="advent,Text Adventure Game,advent.tar"
> a=`expr index "$string" ,`
> title=${string:0:$a-1}
	...
	...
> "expr index" command does work but I don't seem to be able to find enough

My RedHat 7.0 installation has /usr/bin/expr (and /bin/ash). Changing:
	a=`expr index "$string" ,`
to:
	a=`/usr/bin/expr index "$string" ,`
gives the same result when the first line of the script is:
	#!/bin/ash
as the original line does when the first line of the script is:
	#!/bin/bash

ELKS doesn't seem to have the external "expr" executable but, since it's
part of RedHat's "sh-utils" package, Linux source code should be easy to
find. I have no idea if it needs modification to compile for ELKS.

Unfortunately, "${ ... }" still doesn't work. You might have to find some
other external executable(s) for those lines.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: ash and String Manipulation
  2003-01-04  9:50 ` jb1
@ 2003-01-06 11:12   ` Neil Holmes
  2003-01-07 11:04     ` jb1
  0 siblings, 1 reply; 10+ messages in thread
From: Neil Holmes @ 2003-01-06 11:12 UTC (permalink / raw)
  To: jb1; +Cc: Linux 8086

Thanks for this. I am now working on alternative ways.

Looks like I am having to flex my not-so-advanced 'C' skills ! Its going
well though.

Thanks

Neil

-----Original Message-----
From: linux-8086-owner@vger.kernel.org
[mailto:linux-8086-owner@vger.kernel.org]On Behalf Of jb1@btstream.com
Sent: 04 January 2003 09:50
To: Neil Holmes
Cc: Linux 8086
Subject: Re: ash and String Manipulation


On Fri, 3 Jan 2003, Neil Holmes wrote:

> Not sure if there is anyone out there in elks-land that can make some
> suggestions here ?
	...
> Here is a segment of a test script from my EDE Package work :-
>
> string="advent,Text Adventure Game,advent.tar"
> a=`expr index "$string" ,`
> title=${string:0:$a-1}
	...
	...
> "expr index" command does work but I don't seem to be able to find enough

My RedHat 7.0 installation has /usr/bin/expr (and /bin/ash). Changing:
	a=`expr index "$string" ,`
to:
	a=`/usr/bin/expr index "$string" ,`
gives the same result when the first line of the script is:
	#!/bin/ash
as the original line does when the first line of the script is:
	#!/bin/bash

ELKS doesn't seem to have the external "expr" executable but, since it's
part of RedHat's "sh-utils" package, Linux source code should be easy to
find. I have no idea if it needs modification to compile for ELKS.

Unfortunately, "${ ... }" still doesn't work. You might have to find some
other external executable(s) for those lines.

-
To unsubscribe from this list: send the line "unsubscribe linux-8086" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html




^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: ash and String Manipulation
  2003-01-07 11:04     ` jb1
@ 2003-01-07 11:02       ` Neil Holmes
  2003-01-07 12:42       ` Alan Cox
  1 sibling, 0 replies; 10+ messages in thread
From: Neil Holmes @ 2003-01-07 11:02 UTC (permalink / raw)
  To: jb1; +Cc: Linux 8086

I have replaced much of the "toy" code now with a c program.

Thanks for the tip though.

Neil

-----Original Message-----
From: jb1@btstream.com [mailto:jb1@btstream.com]
Sent: 07 January 2003 11:04
To: Neil Holmes
Cc: Linux 8086
Subject: RE: ash and String Manipulation


On Mon, 6 Jan 2003, Neil Holmes wrote:

> Thanks for this. I am now working on alternative ways.
> 
> Looks like I am having to flex my not-so-advanced 'C' skills ! Its going
> well though.

I'm sure your example was just a "toy", but maybe you can simply use 
"sed" to substitute a spaces for each commas, e.g.:
  echo "advent,Text Adventure Game,advent.tar" | sed 's/,/ /g'

I've hardly used the command at all, but I know it's a great deal more
flexible (and cryptic!) than the example above implies. Unfortunately, the
man and info pages are insufficient, but I've collected some more useful
documentation. Let me know if you want that information.

ELKS doesn't seem to have "sed", but should (hint, hint). There's a
message in the archives at http://linmodems.org from Jeff Chua dated Thu,
2 Jan 2003 08:35:50 +0800 (SGT) in which he has identical text
substitutions using "sed" and "ex". The "vi" in my RedHat 7.0 is actually
"vim" and has a command-line switch, "-e", that's supposed to start it in 
"ex" mode. ELKS has "vi", but it doesn't recognize the "-e" switch; maybe 
it would be easier to add that function than to convert "sed" for ELKS.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: ash and String Manipulation
  2003-01-06 11:12   ` Neil Holmes
@ 2003-01-07 11:04     ` jb1
  2003-01-07 11:02       ` Neil Holmes
  2003-01-07 12:42       ` Alan Cox
  0 siblings, 2 replies; 10+ messages in thread
From: jb1 @ 2003-01-07 11:04 UTC (permalink / raw)
  To: Neil Holmes; +Cc: Linux 8086

On Mon, 6 Jan 2003, Neil Holmes wrote:

> Thanks for this. I am now working on alternative ways.
> 
> Looks like I am having to flex my not-so-advanced 'C' skills ! Its going
> well though.

I'm sure your example was just a "toy", but maybe you can simply use 
"sed" to substitute a spaces for each commas, e.g.:
  echo "advent,Text Adventure Game,advent.tar" | sed 's/,/ /g'

I've hardly used the command at all, but I know it's a great deal more
flexible (and cryptic!) than the example above implies. Unfortunately, the
man and info pages are insufficient, but I've collected some more useful
documentation. Let me know if you want that information.

ELKS doesn't seem to have "sed", but should (hint, hint). There's a
message in the archives at http://linmodems.org from Jeff Chua dated Thu,
2 Jan 2003 08:35:50 +0800 (SGT) in which he has identical text
substitutions using "sed" and "ex". The "vi" in my RedHat 7.0 is actually
"vim" and has a command-line switch, "-e", that's supposed to start it in 
"ex" mode. ELKS has "vi", but it doesn't recognize the "-e" switch; maybe 
it would be easier to add that function than to convert "sed" for ELKS.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ash and String Manipulation
  2003-01-07 12:42       ` Alan Cox
@ 2003-01-07 12:12         ` Al Riddoch
  2003-01-07 12:52           ` Paul Nasrat
  0 siblings, 1 reply; 10+ messages in thread
From: Al Riddoch @ 2003-01-07 12:12 UTC (permalink / raw)
  To: linux-8086

[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

On Tue, Jan 07, 2003 at 12:42:25PM +0000, Alan Cox wrote:
> On Tue, 2003-01-07 at 11:04, jb1@btstream.com wrote:
> > substitutions using "sed" and "ex". The "vi" in my RedHat 7.0 is actually
> > "vim" and has a command-line switch, "-e", that's supposed to start it in 
> > "ex" mode. ELKS has "vi", but it doesn't recognize the "-e" switch; maybe 
> > it would be easier to add that function than to convert "sed" for ELKS.
> 
> There are several small sed implementations. One obvious candidate is
> the sed from http://www.tuxedo.org/~esr/software.html
> 

I'm sure I got this version working with ELKS at some point many years ago.
It was pretty easy to build having been written to run on Minix systems
with similar resource constraints.

Al

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: ash and String Manipulation
  2003-01-07 11:04     ` jb1
  2003-01-07 11:02       ` Neil Holmes
@ 2003-01-07 12:42       ` Alan Cox
  2003-01-07 12:12         ` Al Riddoch
  1 sibling, 1 reply; 10+ messages in thread
From: Alan Cox @ 2003-01-07 12:42 UTC (permalink / raw)
  To: jb1; +Cc: Neil Holmes, Linux 8086

On Tue, 2003-01-07 at 11:04, jb1@btstream.com wrote:
> substitutions using "sed" and "ex". The "vi" in my RedHat 7.0 is actually
> "vim" and has a command-line switch, "-e", that's supposed to start it in 
> "ex" mode. ELKS has "vi", but it doesn't recognize the "-e" switch; maybe 
> it would be easier to add that function than to convert "sed" for ELKS.

There are several small sed implementations. One obvious candidate is
the sed from http://www.tuxedo.org/~esr/software.html



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ash and String Manipulation
  2003-01-07 12:12         ` Al Riddoch
@ 2003-01-07 12:52           ` Paul Nasrat
  2003-01-07 13:57             ` Al Riddoch
  2003-01-09  9:37             ` sed-1.3 problems [WAS: Re: ash and String Manipulation] jb1
  0 siblings, 2 replies; 10+ messages in thread
From: Paul Nasrat @ 2003-01-07 12:52 UTC (permalink / raw)
  To: linux-8086

On Tue, Jan 07, 2003 at 12:12:02PM +0000, Al Riddoch wrote:

Wow I didn't know you were still following ELKS :)

> > There are several small sed implementations. One obvious candidate is
> > the sed from http://www.tuxedo.org/~esr/software.html

I'm pretty sure I've seen this working on elks too.

Quick check, compiles ok under elksemu

[pauln@host sed]$ file sed
sed: Linux-8086 executable not stripped
[pauln@host sed]$ echo foo bar baz | ./sed 's/foo/bar/'
bar bar baz

Paul

diff -ruN sed-minix/Makefile sed/Makefile
--- sed-minix/Makefile	Mon Jun  1 17:46:50 1998
+++ sed/Makefile	Tue Jan  7 12:45:24 2003
@@ -2,14 +2,16 @@
 
 VERSION=1.3
 
-CFLAGS=-g
-LFLAGS=-lg
+CFLAGS=-0
+CC=bcc
+CPP=gcc -E
+#LFLAGS=-lg
 
 sed: sedcomp.o sedexec.o
-	cc $(LFLAGS) sedcomp.o sedexec.o -o sed
+	bcc $(LFLAGS) sedcomp.o sedexec.o -o sed
 
 mnsed: mnsed.c
-	cc $(LFLAGS) mnsed.c -o mnsed
+	bcc $(LFLAGS) mnsed.c -o mnsed
 
 sedcomp.o: sedcomp.c sed.h
 sedexec.o: sedexec.c sed.h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: ash and String Manipulation
  2003-01-07 12:52           ` Paul Nasrat
@ 2003-01-07 13:57             ` Al Riddoch
  2003-01-09  9:37             ` sed-1.3 problems [WAS: Re: ash and String Manipulation] jb1
  1 sibling, 0 replies; 10+ messages in thread
From: Al Riddoch @ 2003-01-07 13:57 UTC (permalink / raw)
  To: linux-8086

[-- Attachment #1: Type: text/plain, Size: 251 bytes --]

On Tue, Jan 07, 2003 at 12:52:10PM +0000, Paul Nasrat wrote:
> On Tue, Jan 07, 2003 at 12:12:02PM +0000, Al Riddoch wrote:
> 
> Wow I didn't know you were still following ELKS :)
> 

I lurk, but don't always have time to read everything.

Al

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* sed-1.3 problems [WAS: Re: ash and String Manipulation]
  2003-01-07 12:52           ` Paul Nasrat
  2003-01-07 13:57             ` Al Riddoch
@ 2003-01-09  9:37             ` jb1
  1 sibling, 0 replies; 10+ messages in thread
From: jb1 @ 2003-01-09  9:37 UTC (permalink / raw)
  To: Paul Nasrat; +Cc: linux-8086

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2638 bytes --]

On Tue, 7 Jan 2003, Paul Nasrat wrote:

> diff -ruN sed-minix/Makefile sed/Makefile
> --- sed-minix/Makefile	Mon Jun  1 17:46:50 1998
> +++ sed/Makefile	Tue Jan  7 12:45:24 2003
> @@ -2,14 +2,16 @@
>  
>  VERSION=1.3
>  
> -CFLAGS=-g
> -LFLAGS=-lg
> +CFLAGS=-0
> +CC=bcc
> +CPP=gcc -E
> +#LFLAGS=-lg
>  
>  sed: sedcomp.o sedexec.o
> -	cc $(LFLAGS) sedcomp.o sedexec.o -o sed
> +	bcc $(LFLAGS) sedcomp.o sedexec.o -o sed
>  
>  mnsed: mnsed.c
> -	cc $(LFLAGS) mnsed.c -o mnsed
> +	bcc $(LFLAGS) mnsed.c -o mnsed
>  
>  sedcomp.o: sedcomp.c sed.h
>  sedexec.o: sedexec.c sed.h
> -

Paul Nasrat's diff patch to sed-1.3's Makefile seemed inappropriate for 
ELKS, so I edited the Makefile to this:
------ cut ------ cut ------ cut ------ cut ------ cut ------ cut ------
# Makefile for the GNU/MINIX sed utility

## Modified for ELKS:
## eliminate all references to "CFLAGS" and "LFLAGS" then do it like an
## elkscmd program, but from a subdirectory at the same level as the 
## elkscmd subdirectory
## -- JB

VERSION=1.3

BASEDIR=../elkscmd
include $(BASEDIR)/Make.defs
include $(BASEDIR)/Make.rules
 
sed: sedcomp.o sedexec.o
	bcc sedcomp.o sedexec.o -o sed

mnsed: mnsed.c
	bcc mnsed.c -o mnsed

sedcomp.o: sedcomp.c sed.h
sedexec.o: sedexec.c sed.h

FILES = READ.ME BUGS Makefile sed.h sedcomp.c sedexec.c mnsed.c ctrans sedtest sed.1 sed.lsm

sed-$(VERSION).tar: $(FILES)
	tar -cvf sed-$(VERSION).tar $(FILES)

sed-$(VERSION).tar.gz: sed-$(VERSION).tar
	gzip sed-$(VERSION).tar

clean:
	rm -f sed sedcomp.o sedexec.o mnsed

------ cut ------ cut ------ cut ------ cut ------ cut ------ cut ------

The command "make sed" compiled a program that works correctly under
elksemu for both "sedtest" included in sed-1.3.tar.gz and a
similarly-constructed test I cobbled from "BUGS" in sed-1.3.tar.gz (note:
the reported bug is *not* present). However, when run under ELKS (with
"meminfo" reporting 166KB free) both test programs fail with the error
message "not enough memory". Issuing the first "script" of "sedtest" from
the keyboard:
	sed -e "s/test file/result file/" sedtest
works correctly, but doing the same with the second "script":
	sed -e "/delete/d" sedtest
just hangs. Reducing POOLSIZE (the size of the string-pool space) in 
sedcomp.c from 10000 to 6000 (as it is in mnsed.c) didn't help.

Issuing the command "make mnsed" spews error messages.

I've attached "bugstest" as a zip file so that the tab characters aren't 
altered.

Note: When running "sedtest" or "bugtest" under elksemu the sed command in 
each *must* be edited to "./sed" or similar, otherwise the Linux version 
rather than the ELKS version will be executed.

[-- Attachment #2: Type: APPLICATION/zip, Size: 301 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-01-09  9:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-03 21:24 ash and String Manipulation Neil Holmes
2003-01-04  9:50 ` jb1
2003-01-06 11:12   ` Neil Holmes
2003-01-07 11:04     ` jb1
2003-01-07 11:02       ` Neil Holmes
2003-01-07 12:42       ` Alan Cox
2003-01-07 12:12         ` Al Riddoch
2003-01-07 12:52           ` Paul Nasrat
2003-01-07 13:57             ` Al Riddoch
2003-01-09  9:37             ` sed-1.3 problems [WAS: Re: ash and String Manipulation] jb1

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.