#save the next shell as readfile.sh
#======================================
#!/usr/bin/bash filename="$1"
while IFS= read -r line || [[ -n "$line" ]]; do # Do what you want to $line echo "Text read from file: $line"
done < "${filename}"#======================================ref:
https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable
chmod +X readfile.sh
./readfile.sh test.txt
没有评论:
发表评论