It is currently Tue, 30 Nov 2021 18:13:15 GMT



 
Author Message
 HELP! read in Bourne shell script
I have a small Bourne shell script, where i loop through the files in a
directory to make a translation of the files. First line of the file
contains a dataname which is to be used as the name for the converted file.
In some instances it is neccesary to change the name to something else to
get a meaningfull filename, so I wan't the script to write the suggested
name and prompt for an alternative name. I made the following construction,
but the script wont stop at the read statement within the while loop.

#!/bin/sh
/bin/ls|while read name
do
   partname=`head -1 $name|tr -d "-"| tr " " "_"|cut -c1-8`
   echo "Suggested filename "$partname
   echo "Enter alternative filename : \c"
   read altname
   translate i=$name o=$altname
done

The construction within the while loop works if placed outside the loop, but
within the loop the script just continues with $altname containing an empty
string.

Any suggestions ???

Claus Dalsgaard
ICEM support
Control Data A/S, Denmark

All std disclaimers apply.



 Sun, 13 Apr 1997 19:18:04 GMT   
 HELP! read in Bourne shell script

I am trying to get some feed back on Computer Associates CA-Unicenter client/server software. Is it a worthwhile product or crap? What are some other applications that compete with CA-Unicenter? Any and all info will help me.

Scott



 Sun, 13 Apr 1997 22:56:45 GMT   
 HELP! read in Bourne shell script
: I have a small Bourne shell script, where i loop through the files in a
: directory to make a translation of the files. First line of the file
: contains a dataname which is to be used as the name for the converted file.
: In some instances it is neccesary to change the name to something else to
: get a meaningfull filename, so I wan't the script to write the suggested
: name and prompt for an alternative name. I made the following construction,
: but the script wont stop at the read statement within the while loop.

: #!/bin/sh
: /bin/ls|while read name
: do
:    partname=`head -1 $name|tr -d "-"| tr " " "_"|cut -c1-8`
:    echo "Suggested filename "$partname
:    echo "Enter alternative filename : \c"
:    read altname
:    translate i=$name o=$altname
: done

Try this:

for name in `/bin/ls`
do
   <existing code>
done

------------------------------------------------------------------------
  __________________________     |  Steve Thompson
 (__ |_ _|_  _  _ _ __  _  :)    |  SysAdmin@Work:(@Play:)
 ___)|_)|| |(_)| | ||_)/_)       |  sbtho...@wrdis01.robins.af.mil
--------------------|--------------------------------------------------
 The person who says it cannot be done should  
  not interrupt the person who is doing it ;)    -- Chinese Proverb
------------------------------------------------------------------------



 Mon, 14 Apr 1997 20:03:32 GMT   
 HELP! read in Bourne shell script

add the following after to do
        if [ "$name" = "" ]; then
                break
        fi

Good luck.

Jim Deardorff

- Show quoted text -



 Mon, 14 Apr 1997 19:28:13 GMT   
 HELP! read in Bourne shell script

Your problem is that one input-stream is uzed for all "read"s, and you
want one for "ls"-output and another for other-name reding.  In "ksh" one
can split the input with "read -uD", where D is a digit.  Here you can
        A change " ... ls | while read ... " to " for name in `/bin/ls` "
or      B tack "< /dev/tty" after the "read" that is meant for reding the
          other file-name
By the wai, "sed" can doo all that you hav a long pipe-line doo for "partname":
        sed -n '1 {
        s/-//g
        s/ /_/g
        s/\(........\).*/\1/
        p
        }'

In this article he writes

This is not relevant to your problem, and furthermore in bad style.
Either is better:
        if [ "$name" = "" ]
        then    break
        fi
or
        [ "$name" = "" ] && break



 Sun, 27 Apr 1997 10:29:10 GMT   
 
   [ 5 post ] 

Similar Threads

1. help in learning how to do Bourne shell scripts then converting them to csh scripts

2. A Solaris 8 (Bourne Shell) Scripting question, regarding a log rotation script

3. HELP! bourne shell bug (setuid scripts)


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software