繁体   English   中英

Bash脚本读取文件:参数列表太长

[英]Bash script read file:argument list too long

我的密码

#!/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

为什么?

空格很重要。

这不是分配-而是运行名为file的命令,并带有一个以=开头的参数列表,该参数列表由文件262_V01_C00_R000_TEx_BL_2048H.dat的内容组成(字符串拆分和glob扩展)(时间太长,放在参数列表上):

# 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM