Like in the Title I tried to write a bash loop with if and else settings but while the if part works for now but the else part does not do anything it should
#!/bin/bash
x=30
echo "Input No."
read y
z=29-y
if [ $y > 29 ]
then
while (( $x <= $y ))
do
echo "TEST-No.$x" >> /home/TEST/test
x=$(($x+1))
done
else
while (($z>0))
do
sed -i '$d' /home/TEST/test
z=$(($z-1))
done
fi
cat /home/TEST/test
if y>29 then it should write the line TEST-No.$x into the file test till x<y
root@TEST:/home/TEST# ./loop
Input No.
30
TEST-No.1
TEST-No.2
TEST-No.3
TEST-No.4
...
TEST-No.29
TEST-No.30
if y<=29 then if should delete the last line of the file till z = 0
root@TEST:/home/TEST# ./loop
Input No.
10
TEST-No.1
TEST-No.2
TEST-No.3
TEST-No.4
...
TEST-No.29