02-12-04 06:36 AM
John wrote:
>
> I'm getting the following errors when I run the following script
> (named sedscript.sh):
>
> #!/bin/ksh
> cat <(dd if=invfile bs=1 count=359) <(print -n "ABCDE") <(dd
> if=invfile skip=364 bs=1) > outputfile.txt
>
> + dd if=invfile bs=1 count=359
> + cat /dev/fd/4 /dev/fd/5 /dev/fd/6 invfile # HUH?????????????
Is this Solaris? /dev/ file discriptors / file number makes sense
in this context but I didn't know that Korn shell used them as
strings in commands.
But think about what you did. You opened 3 subshells producing
output and set them each to be input to the cat. Sure enough cat
reads the files on the command lines. Picking 4, 5 and 6 only
says the shell had something else open for 2 and 3 before then.
I'm not comfortable with doing more than one redirection of input,
though. It sets up a race condition: Commands in parens or back
ticks get run asynchronously without specified order or timing.
Arrow redirection happens the "the" command is started. But the
cat is "the" command in that case, not the subshells.
> + print -n ABCDE
> + dd if=invfile skip=364 bs=1
> + 1> outputfile.txt
> sedscript.sh[2]: cat: /dev/fd/4: cannot open [No such file or
> directory]
> sedscript.sh[2]: cat: /dev/fd/5: cannot open [No such file or
> directory]
> sedscript.sh[2]: cat: /dev/fd/6: cannot open [No such file or
> directory]
> 359+0 records in
> 359+0 records out
So it appears to me that it set up the redirections, launched the
cat attached to them, expected the cat to wait for its input, and
on a separate timetable started up the other images in the pipe.
Since it launched the first dd before the cat, I'm surprised it
failed on /dev/fd/4, but I'm not surprised that it failed on the
other two.
> Can someone see what I've typed incorrectly in this script? What's
> the deal with all the cat /dev/fd errors and why ABCDE is still not
> being inserting into my file?
Work on a simpler I/O redirection scheme. The man page for the
shell only gives examples of single arrow commands, so only use single
arrow commands. Bundle all of the parts into a single subshell.
Even better, run the 3 subcommands in order. dd > outputfile,txt,
print >> outputfile.txt, dd >> outpputfile.txt
When fanced with the choice between fancy and coll looking, or
going towards the center of how shells are designed and ugly, move
towards the center of the design.
[ Post a follow-up to this message ]
|