In: Computer Science
Bash scripting return output: Determine the output this code
1. #!/bin/bash
Valid = true
count=1
while [ $valid ]
do
echo $count
if [ $count -eq 5 ];
then
break
fi
((count++))
done
2. #!/bin/bash
num=100
for x in $(seq 1 5)
do
temp=$((num+x))
if [ $temp -1e 103]; then
echo $temp
else
echo "Too Big"
fi
done
3.#!/bin/bash
num=5
for x in $(seq 1 5)
do
echo $((num*x))
done
4. #!/bin/bash
for x in $(seq 1 10)
do
echo $x
done
5. line 1
line 2
line 3
line 4
line 5
head -n4 < data.txt > t1.txt
tail -n1 <t1.txt > out.txt
cat out.txt
NOTE:- I HAVE ATTACHED THE PROGRAM IN A SEQUENCE OF
1.THE CODE WITH SNIPPET
2.SCREENSHOTS OF THE OUTPUT
------ANSWER-------
CODE FOR PROGRAM 1 WITH OUTPUT
valid=true
count=1
while [ $valid ]
do
echo $count
if [ $count -eq 5 ];
then
break
fi
((count++))
done
valid=true
count=1
while [ $valid ]
do
echo $count
if [ $count -eq 5 ];
then
break
fi
((count++))
done
OUTPUT
CODE FOR PROGRAM 2
IN THE PROGRAM 2 THERE WAS 2 ERROR WHICH IS SOLVED
1. IN THE IF CONDITION IT IS -le NOT -1e
2. WE NEED TO PUT 103 IN SINGLE QUOTES '103' LIKE THIS IN THE IF CONDITION
I HAVE ALSO ATTACHED THE OUTPUT OF THE CORRECTED CODE WITH YOUR CODE ALSO.
num=100
for x in $(seq 1 5)
do
temp=$((num+x))
if [ $temp -le '103' ]; then
echo $temp
else
echo "Too Big"
fi
done
num=100
for x in $(seq 1 5)
do
temp=$((num+x))
if [ $temp -le '103' ]; then
echo $temp
else
echo "Too Big"
fi
done
OUTPUT OF CORRECTED CODE
OUTPUT OF YOUR CODE
CODE FOR PROGRAM 3
num=5
for x in $(seq 1 5)
do
echo $((num*x))
done
num=5
for x in $(seq 1 5)
do
echo $((num*x))
done
OUTPUT
CODE FOR PROGRAM 4
for x in $(seq 1 10)
do
echo $x
done
for x in $(seq 1 10)
do
echo $x
done
OUTPUT
CODE FOR PROGRAM 5
FOR PROGRAM 5 WE NEED TO FIRST OF ALL SAVE THE GIVEN DATA INTO A DATA.TXT FILE THEN AND THEN ONLY WE CAN EXECUTE IT.
head -n4 < data.txt > t1.txt
tail -n1 <t1.txt > out.txt
cat out.txt
head -n4 < data.txt > t1.txt
tail -n1 <t1.txt > out.txt
cat out.txt
OUTPUT
Note: If you have any queries then let me know in the comments. If you find it helpful then a Like would be appreciated.