I’m trying to get a dd command in a bash script going with the “if” set to a variable.
The variable may be /dev/zero or may be as complicated as
<(yes $’\01′ | tr -d “\n”)
I can seem to get the latter to work.
write_file=/dev/zero
dd if=$write_file bs=2048 seek=1 of=/dev/sda count=524288
That works.
write_file="<(yes $'\01' | tr -d "\n")"
dd if=$write_file bs=2048 seek=1 of=/dev/sda count=524288
This doesn’t work. I get a
dd: invalid option -- 'd'
Try `dd --help' for more information.
But If I do a straight
dd if=<(yes $'\01' | tr -d "\n") bs=2048 seek=1 of=/dev/sda count=524288
in the script it works fine.
I’m sure there is some escaping that needs to be done but I’m no where near a bash expert to figure out how to do this!
Update: Tried from suggestions below
write_file="<(yes $'\01' | tr -d \"\n\")"
dd if="$write_file" bs=2048 seek=1 of=/dev/sda count=524288
and got
dd: opening `<(yes $\'\\01\' | tr -d "\\n")': No such file or directory
Bash does not parse the content of your variable and pass it directly to dd, which has no idea of what to do with it.
You can force Bash to parse the variable using “eval”: