从文件中读取Bash并将其存储到MATLAB中的变量 [英] Bash read from file and store to variables in MATLAB

查看:58
本文介绍了从文件中读取Bash并将其存储到MATLAB中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Bash中一个非常简单的1行文件中读取2个浮点数.我想将这两个数字存储到变量中.我从Googling看到的所有示例如下:

I'm trying to read 2 floating numbers from a very simple 1-line file in Bash. I want to store these two numbers into variables. All the examples I see from Googling look like:

while read VAR1 VAR2
do
   <command>
done < file.txt

但是,这仅将VAR1VAR2保留在while循环内.如何存储两个变量,以便可以在脚本中的任何地方使用它们?非常感谢!

But this keeps VAR1 and VAR2 inside the while loop only. How can I store the two variables so that I can use them anywhere in my script? Thanks so much!

推荐答案

读取单行文件(如您的问题所述)时,while循环是多余的.

The while loop is superfluous when reading a file with a single line (as described in your question ).

为什么不简单地做:

read VAR1 VAR2 < file.txt
echo $VAR1
echo $VAR2

这将读取文件的第一行

这篇关于从文件中读取Bash并将其存储到MATLAB中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆