Osy Amir PR - 11
Osy Amir PR - 11
loop
Ans.
read -p 'Enter no = ' no
echo "Table of $no"
for (( i=1; i<=10; i++ ))
do
echo " "$(( no * i ))
done
Output :
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$
Exercise
1) Give output of the following a.
a.
NUMBERS="1 2 3 4 5 6 7"
for NUM in $NUMS
do
Q='expr $NUM % 2
if [ SQ -eq 0 ]
then
echo "Number is an even number!!"
continue
fi
echo "Found odd number"
done
Error :-
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$ chmod 777 oddeven.sh
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$./oddeven.sh
./oddeven.sh: line 5: unexpected EOF while looking for matching `''
./oddeven.sh: line 13: syntax error: unexpected end of file
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$
b. #!/bin/sh
a=0
while [ $a -lt 10 |
do
echo $a
if [ $a -eq 5 ]
then
break
fi
a=$(( $a + 1 ))
done
Output:
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$ chmod 777 lessthan.sh
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$ ./lessthan.sh
0
1
2
3
4
5
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$
Output:
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$ chmod 777 fibo.sh
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$ ./fibo.sh
Enter no for fibonacci = 34
Fibonacci of 34 is 9227465
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$
Output :
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$ chmod 777 pattern.sh
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$ ./pattern
bash: ./pattern: No such file or directory
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$ ./pattern.sh
Enter no for pattern = 9
*********
********
*******
******
*****
****
***
**
*
Shaikhamir@shaikh-HP-Laptop-15s-gy0xxx:~$