[Shell Script](EN) Use file or command output in while loop

Process file or result of command in while loop line by line in shell script.


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)


Method Examples

Process command result line by line in while loop

  • Use Pipeline
ls ./Test | while read line
do
	echo $line
done
ls /tmp | while read line
do
	echo $line
done


Process file line by line in while loop

  • Use Redirection
while read line
do
    echo $line
done < test.txt
  • Use Pipeline
cat test.txt | while read line
do
    echo $line
done


Reference

[Python] 파이썬(Python) List Comprehensions

> 파이썬(Python) List Comprehensions에 대해 알아보자.## 환경- Linux- Python 3.X.X## 파이썬(Python) List Comprehensions### List Comprehensions```pythonre...… Continue reading