Write a shell script called hello that takes one argument at the command line: h
ID: 3724238 • Letter: W
Question
Write a shell script called hello that takes one argument at the command line: hello < the person’s name > Within the script, count backward from 10, displaying each number; and then end with "Hello, < the person’s name >, I am a HAL 9000". Your application should be able to handle up to three values, e.g, “Donald”, “Donald Trump”, or “Mr. Donald Trump” can all be valid input. Next, populate an array called “presidents” and fill it with the following values: Lyndon B. Johnson Richard Nixon Gerald Ford Jimmy Carter Ronald Reagan George H.W. Bush Bill Clinton George W. Bush Barack Obama Donald J. Trump Then traverse the array, printing out each value thusly: Lyndon B. Johnson 36th president Richard Nixon 37th president Gerald Ford 38th president and so on.
Explanation / Answer
#!/bin/bash
b=10
while [ $b -gt 0 ]
do
echo $b
b=`expr $b - 1`
done
echo Hello, $1 $2 $3, I am HAL 9000
presidents[0]="Lyndon B. Johnson"
presidents[1]="Richard Nixon"
presidents[2]="Gerald Ford"
presidents[3]="Jimmy Carter"
presidents[4]="Ronald Reagan"
presidents[5]="George H.W. Bush"
presidents[6]="Bill Clinton"
presidents[7]="George W. Bush"
presidents[8]="Barack Obama"
presidents[9]="Donald J. Trump"
a=0
i=37
while [ $a -lt 10 ]
do
echo "${presidents[$a]}" $i th president
i=`expr $i + 1`
a=`expr $a + 1`
echo
done
Make sure no spaces get added between equal to sign.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.