[SOLVED] not getting desired output while using 'while read'
by spalisetty from LinuxQuestions.org on (#4ZVGE)
Hello,
I am trying to use 'while read' to move or redirect the contents of one file to another.
Code:ubuntu@ip-172-31-92-85:~/suman$ cat whileread.sh
#! /bin/bash
cat sleep.sh | while read files
do
echo $files
done
sleepout=$sleep.sh
echo "$sleepout"The output I am getting is like
Code:ubuntu@ip-172-31-92-85:~/suman$ ./whileread.sh
#! /bin/bash
n=1
while [ $n -le 10 ]
do
echo $n
sleep 1
n=$(($n+1))
done
.shCode:ubuntu@ip-172-31-92-85:~/suman$ cat sleep.sh
#! /bin/bash
n=1
while [ $n -le 10 ]
do
echo $n
sleep 1
n=$(($n+1))
done
ubuntu@ip-172-31-92-85:~/suman$I don't why .sh is part of the output for ./whileread. Please help.


I am trying to use 'while read' to move or redirect the contents of one file to another.
Code:ubuntu@ip-172-31-92-85:~/suman$ cat whileread.sh
#! /bin/bash
cat sleep.sh | while read files
do
echo $files
done
sleepout=$sleep.sh
echo "$sleepout"The output I am getting is like
Code:ubuntu@ip-172-31-92-85:~/suman$ ./whileread.sh
#! /bin/bash
n=1
while [ $n -le 10 ]
do
echo $n
sleep 1
n=$(($n+1))
done
.shCode:ubuntu@ip-172-31-92-85:~/suman$ cat sleep.sh
#! /bin/bash
n=1
while [ $n -le 10 ]
do
echo $n
sleep 1
n=$(($n+1))
done
ubuntu@ip-172-31-92-85:~/suman$I don't why .sh is part of the output for ./whileread. Please help.