Write bash script that does the following: It accepts two parameters from the ke
ID: 3801810 • Letter: W
Question
Write bash script that does the following:
It accepts two parameters from the keyboard.
The first parameter is always a word (like cfs264sp1702).
The second parameter is always a number greater than 1, for example 5.
The script has a while loop, inside of which it does the following in every iteration.
It prints the first parameter.
After printing the first parameter, the code prints a number, which is 1 in the first iteration, 2 in the second iteration, etc. (always incrementing by 1 in each iteration).
The loop iterates as many times as the value in the second parameter.
Explanation / Answer
Program:
#!/bin/bash
echo "Enter parameter 1 : "
read p1
echo "Enter parameter 2 : "
read p2
i=1
while [ $i -le $p1 ]
do
echo $p2,$i
#echo $i
i=`expr $i + 1`
done
Result:
Enter parameter 1 :
5
Enter parameter 2 :
asdfsd45s4d5f
asdfsd45s4d5f,1
asdfsd45s4d5f,2
asdfsd45s4d5f,3
asdfsd45s4d5f,4
asdfsd45s4d5f,5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.