我的代码
#!/bin/bash
file =$( < 262_V01_C00_R000_TEx_BL_2048H.dat)
awk '$0+0 == $0 { printf "%.3f\n", $0 / .03 }' file > output
终端
milenko@milenko-HP-Compaq-6830s:~/procmt$ bash a5.sh
a5.sh: line 3: /usr/bin/file: Argument list too long
为什么?
答案 0 :(得分:2)
空白很重要。
这不是一个赋值 - 而是运行名为file
的命令,其参数列表以=
开头,并包含文件262_V01_C00_R000_TEx_BL_2048H.dat
字符串的内容 - split和glob-expanded(碰巧太长而无法放在参数列表中):
# runs the file command with an argument list based on the contents of your .dat file
# will thus fail if the .dat file's contents cannot fit on a UNIX command line
file =$( < 262_V01_C00_R000_TEx_BL_2048H.dat)
此是一项作业:
# reads the contents of your .dat file into the variable named file
# note that this doesn't correctly handle content with NUL literals
file=$(<262_V01_C00_R000_TEx_BL_2048H.dat)
...您可以将阅读的内容反馈到awk
的输入中:
# feed contents of the file variable on stdin to awk
awk '$0+0 == $0 { printf "%.3f\n", $0 / .03 }' <<<"$file" > output
那就是说,你不清楚为什么要尝试将文件的内容分配给一个变量。为什么不直接将awk
连接到文件?
# store filename in a variable
file=262_V01_C00_R000_TEx_BL_2048H.dat
# ...and pass that filename to awk
awk '$0+0 == $0 { printf "%.3f\n", $0 / .03 }' "$file" > output