我正在bash中創建一個程序,它使用我創建的數字創建了一個histoplot。這些數字是這樣存儲的(其中第一個數字是文件的一行上有多少個單詞,第二個數字是給定文件中某一行上該單詞的數量出現的次數。)Bash for loop參數意外行爲
1 1
2 4
3 1
4 2
這應該產生:
1 #
2 ####
3 #
4 ##
,但我得到的輸出是:
1 #
2 #
3 #
4 #
但是for循環是不承認我的變量 「hashNo」 是一個數字。
#!/bin/bash
if [ -e $f ] ; then
while read line
do
lineAmnt=${line% *}
hashNo=${line##* }
#VVVV Problem is this line here VVVV
for i in {1..$hashNo}
#This line ^^^^^^^ the {1..$hashNo}
do
hashes+="#"
done
printf "%4s" $lineAmnt
printf " $hashes\n"
hashes=""
done < $1
fi
,如果我與一些替代hashNo代碼工作(例如:4,使4個哈希在我的輸出),但它需要能夠與各行改變(在文件中沒有的所有行都會有相同的金額在這些字符
感謝您的幫助:d
重複許多許多問題。 –