English 中文(简体)
从 txt 行读取整数
原标题:read integer from txt line

我有Txt文件 3行。

用户$ cat 文件. txt

5 - 确定循环结束需要使用的整数

1 - 一种逻辑,它表明后期条件是否真实或虚假

fold_nam - 文件夹的名称 。

我现在想将第一行划为整数, 到目前为止我所做的是:

回声 $( sed - n 1p 文件. txt) & gt; 循环_ end

但当我试图用文件工作时 我什么都拿不到

例如: 当我做以下操作时, 我从 txt 文件得到一条空白行, 而不是数值 。

用户元回声 $loop_ end

我在这里的一些论坛里读到过这个问题, 并稍稍发发热, 似乎需要转换价值(BTW,

使用右侧命令行的帮助... tnx

最佳回答

指定输出到类型整数的 loop_end 变量。 您所做的是将输出重定向为名为 loop_end 的文件 。

declare -i loop_end=$(sed -n 1p file.txt)
echo $loop_end
问题回答

使用 read 内嵌的按键将允许您读取文件内容, 例如 :

read loop_end < file.txt




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签