Wednesday, June 2, 2021

Looping with numbers

 HACKERANK SOLUTIONS, LINUX SCRIPTING 

Use a for loop to display the natural numbers from  to .

Input Format

There is no input

Output Format

1
2
3
4
5
.
.
.
.
.
50
SOLUTION
Syntax for For Loop: 
for varname in list
do 
  Statements
done

CODE

for i in {1..50} do echo $i done

A Personalized Echo

 HACKERANK SOLUTIONS, LINUX SCRIPTING 

Write a Bash script that accepts  as input and displays the greeting "Welcome (name)"

Input Format

There is one line of text,.

Output Format

One line: "Welcome (name)" (quotation marks excluded).
The evaluation will be case-sensitive.

Sample Input 0

Dan  

Sample Output 0

Welcome Dan  

Sample Input 1

Prashant

Sample Output 1

Welcome Prashant
Solution

Here, the read commad is used to take input from the user . 

CODE

read name
echo "Welcome" $name
 

Tuesday, June 1, 2021

Loops

HACKERANK SOLUTIONS, LINUX SCRIPTING 

 Your task is to use for loops to display only odd natural numbers from to.

Input Format

There is no input.

Constraints

-

Output Format

1
3
5
.
.
.
.
.
99  

Sample Input

-

Sample Output

1
3
5
.
.
.
.
.
99  
SOLUTION

-ne : Not Equal

code: 

for((i=0;i<100;i++))
do
x=$((i%2))
if [ $x -ne 0 ]
then
echo "$i"
fi
done