|
Home > Archive > Unix questions > February 2004 > Help needed with dd command
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Help needed with dd command
|
|
|
| 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?????????????
+ 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
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?
| |
| Bill Marcum 2004-02-11, 4:36 am |
| ["Followup-To:" header set to comp.unix.admin.]
On 11 Feb 2004 06:25:07 -0800, John
<pokechoppe@aol.com> 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
>
What flavor of Unix? What version of ksh? It seems like you may have
found a bug, the question is, do you need to update your software or
report the bug, and to whom (kornshell.com or the pdksh maintainers)?
You could rewrite your script without using <( ):
dd if=invfile bs=1 count=359 > outputfile.txt
print -n "ABCDE" >> outputfile.txt
dd if=invfile skil=364 bs=1 >> outputfile.txt
--
Think of your family tonight. Try to crawl home after the computer crashes.
| |
| Chris F.A. Johnson 2004-02-11, 6:36 am |
| On Wed, 11 Feb 2004 at 14:25 GMT, 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?????????????
> + 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
>
> 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?
Don't make it more complicated than necessary:
{
dd if=invfile bs=1 count=359
printf "ABCDE"
dd if=invfile skip=364 bs=1
} > outputfile.txt
--
Chris F.A. Johnson http://cfaj.freeshell.org
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
| Doug Freyburger 2004-02-12, 1: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.
|
|
|
|
|