i want to count number of lines in a file and assi

2019-08-21 04:33发布

问题:

I want to count number of lines in a files and assign that integer to a variable. I am using below code but not able to get through

Shell

#!/bin/bash
file=hostname.txt
n= $( wc -l hostname.txt | awk '{ print $1 }' ) #assigning number of lines to a variable but not able to do so 
i=1
while read -r line
do
while [ $i -le $n ]
        do
echo "==============$i=================$n================================"

i=$((i+1))
done
done < "$file"
==============1=================2================================
==============2=================2================================
标签: shell