[英]BASH: trying to read in file but it only gets the first line
我正在嘗試讀取 bash 中的文件並存儲稍后要使用的變量,文件格式如下
姓名縮寫
價格 數量 maxQuantitiy
商品描述
但是當我嘗試實際讀取文件時,它似乎只在每個變量中存儲了第一行,並且想知道它存儲變量的位置是錯誤的
if [ -r data/$fileName.file ]; then
read name abbreviation < data/$fileName.file
read price quantity maxQuantity < data/$fileName.file
read itemDescription < data/$fileName.file
fi
當我嘗試回應價格或數量時,它回應了名稱和縮寫。
read
讀取第一行。 當您進行另一個重定向時,它不會與前一個重定向相關聯,因此它會再次讀取第一行。 您需要對所有讀取使用一個重定向:
if [ -r data/$fileName.file ]; then
{
read name abbreviation
read price quantity maxQuantity
read itemDescription
} < data/$fileName.file
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.