简体   繁体   English

如何将ash中的文件内容读入参数?

[英]How to read a file content in ash into an argument?

I'm trying to read a file which holds a single number in ash shell. 我正在尝试读取在ash shell中包含一个数字的文件。 The bash way of doing so 这样做的重击方式

ARG=`cat /tmp/tempfile`

doesn't work and I get that ARG doesn't hold anything after this line of code. 不起作用,我知道在这行代码之后ARG不保存任何内容。

try to surround it with quotes to have it not stopped at the first newline: 尝试用引号引起来,以使它不会在第一行换行符处停止:

ARG="`cat /tmp/tempfile`"

or 要么

ARG="$(cat /tmp/tempfile)"

or 要么

read ARG  </tmp/tempfile #only 1st line will be read

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

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