1

I have written my first bash script which salvages historic 6800 mdos files currently stored on a large collection of 8-inch floppy disks. The script supplies arguments to an executable file that [a] lists files on the disk image then [b] gets each file one by one and saves it to a directory on the hard drive. The executable is compiled from source code written by Joseph H Allen.

    C:/TEST/mdos.exe floppy.img ls -1 > filelist                             # list filenames one per line ;
    while read -r name; do
    echo -e "${name}"
    C:/TEST/mdos.exe floppy.img get $name C:/TEST/MDOS/$name > loadstart     # capture load & start addresses
    done < filelist

Files successfully recovered from a single floppy disk image are shown here. enter image description here

I'm now trying to document the archiving process by capturing the two interleaved strings of stdout that appear on the screen whenever the script runs. These strings originate in two separate lines where the executable is run.

The first lists all filenames found on the disk image in response to an ls argument supplied to the mdos.exe at run time. Each filename appears on successive lines.

    C:/TEST/mdos.exe floppy.img ls -1

The second displays load and start addresses that some mdos 6800 command files used at run time.

    C:/TEST/mdos.exe floppy.img get $name C:/TEST/MDOS/$name

On the screen both streams are interleaved like so

    a.lo
    Load=$2000, Start=$2000
    a.sa
    ad571.cm
    Load=$6000, Start=$6000
    sd571c.sa
    b2716.cm
    Load=$2000, Start=$2002
        ...

Whenever there's a load address start address message it would make more sense on a printed log if it appeared on the same line as the file that reported it, like so

desired format

    a.lo      Load=$2000, Start=$2000
    a.sa
    ad571.cm  Load=$6000, Start=$6000
    ad571c.sa
    b2716.cm  Load=$2000, Start=$2002
    ...

I have so far managed to save the first stdout stream to file but not the second.

While I understand arguments for avoiding ls presented in posts here here and here, the part of my script that currently works uses ls, an argument required by mdos.exe. Unfortunately it happens to be spelt the same way and is functionally similar to ls in Linux. I really can't tell if that is causing the obvious problem : how to capture the load and start addresses. Ultimately I need to capture both stdout streams and present them on the same line in the desired print format (above). Looking at posts here here here and here it seems like I should be using an associative array to do this instead of writing two separate files.

If this is the best way to proceed, how would this be done as a single loop ? or should it use a separate loop to capture each stream ?

Greg
  • 1,750
  • 2
  • 29
  • 56
  • Sooooo `echo -ne "${name} "` ? Also `>` _overwrites_ the file each loop, use `>>` to append to file. – KamilCuk Sep 05 '21 at 07:10
  • Good point. That could well hide the problem. Checking – Greg Sep 05 '21 at 07:45
  • Good suggestion. `>>` made no difference but the `/n` option will definitely solve this with a bit of tweaking. This is what it gave a.loLoad=$2000, Start=$2000 a.saad571.cmLoad=$6000, Start=$6000 ad5713.cmLoad=$6000, Start=$6000 ad571c.sab2716.cmLoad=$2000, Start=$2002 If you'd like to post an answer I'll accept it – Greg Sep 05 '21 at 08:02

1 Answers1

1

Seems like you would want to:

while IFS= read -r name; do
       echo -ne "${name} "
       # capture load & start addresses
       C:/TEST/mdos.exe floppy.img get "$name" "C:/TEST/MDOS/$name"
done < filelist > loadstart

Check your scripts with shellcheck.net .

You could do for example printf "%-20s" "$name" to offset it better.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • I made the space a '\t' so filenames are kept in a separate column to the load & start address messages. Much appreciated – Greg Sep 05 '21 at 08:14