【发布时间】:2023-04-06 13:23:01
【问题描述】:
我正在尝试在 bash 脚本中获取 dd 命令,并将“if”设置为变量。 变量可能是 /dev/zero 或者可能很复杂
我似乎可以让后者工作。
write_file=/dev/zero
dd if=$write_file bs=2048 seek=1 of=/dev/sda count=524288
这行得通。
write_file="<(yes $'\01' | tr -d "\n")"
dd if=$write_file bs=2048 seek=1 of=/dev/sda count=524288
这不起作用。我得到一个
dd: invalid option -- 'd'
Try `dd --help' for more information.
如果我做顺子
dd if=<(yes $'\01' | tr -d "\n") bs=2048 seek=1 of=/dev/sda count=524288
在脚本中它工作正常。
我确定需要进行一些转义,但我还没有 bash 专家来弄清楚如何做到这一点!
更新:尝试以下建议
write_file="<(yes $'\01' | tr -d \"\n\")"
dd if="$write_file" bs=2048 seek=1 of=/dev/sda count=524288
得到了
dd: opening `<(yes $\'\\01\' | tr -d "\\n")': No such file or directory
【问题讨论】:
-
试试
dd "if=$write_file" ... -
就行了。见BashFAQ/050。
标签: bash process substitution