Question

2-variables-galore.sh #!/bin/bash set -u greeting="Hello" name = $1 if [[ -z $name ]]; then echo "You...

2-variables-galore.sh

#!/bin/bash

set -u

greeting="Hello"

name = $1

if [[ -z $name ]]; then

echo "You need to tell me your name!"

echo " $0 "

exit -1

else

echo "$greetig $name"

fi

while [[ $i < 4 ]]; do

echo "i is currently $i"

i=$((i+1))

elihw

set +u

exit 0

There are four (4) problems with this script. Above is an example output of the script.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/bash
set -u
greeting="Hello"
name=$1 #need to remove spaces in between words and =
if [[ -z $name ]]; then
echo "You need to tell me your name!"
echo " $0 "
exit -1
else
echo "$greeting $name" #need greeting word here because we have used above not greetig
fi
i=0 # need to initialize the i value because we are comparing with < 4 in while loop
while [[ $i < 4 ]]; do
echo "i is currently $i"
i=$((i+1));
set +u
done #need this to complete the loop
exit 0

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)

Add a comment
Know the answer?
Add Answer to:
2-variables-galore.sh #!/bin/bash set -u greeting="Hello" name = $1 if [[ -z $name ]]; then echo "You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1 #!/bin/bash 3 usrprocs() { 4 if [ ! $1 ]; then 5 echo "$1 <username>...

    1 #!/bin/bash 3 usrprocs() { 4 if [ ! $1 ]; then 5 echo "$1 <username> 6 return 1 7 fi 8 id - U $1 >> /dev/null 2>&1 9 if [ "$?" != 0 ]; then 10 echo "$1 is not a valid username" 11 return 1 12 fi 13 count=$(ps - U $1 | Wc-1) 14 echo "$1 has $count processes 15 } 4. In this exercise, you will be modifying the function you created in Q3. Store...

  • Hello! In this bash program, there is an error when i try to execute it. I am running it on Unix and I used emacs for the text editor it says: line 3: [0: command not found line 9: if[-f ]: command no...

    Hello! In this bash program, there is an error when i try to execute it. I am running it on Unix and I used emacs for the text editor it says: line 3: [0: command not found line 9: if[-f ]: command not found line 10: syntax error near unexpected token `then' line 10: `then' ------------------------------- #!/bin/bash if [ $# != 1 ] then echo "Usage: myScript.sh " exit 1 fi if [ -f $1 ] then awk ' BEGIN...

  • Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment...

    Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment to tell us what you did, why and how. 3. allows a user to enter their name and a number between 1 than 100 (this must be prompted so the user knows what to do) 4. creates a random number between 1 and 100 for you to guess. The command to create a random number is shown below. (if you find a better one...use...

  • 1. Write 4 simple shell scripts. Each question will ask you to write one or more...

    1. Write 4 simple shell scripts. Each question will ask you to write one or more command lines to solve a problem. Put the command(s) from each problem into a file named problem1.sh, problem2.sh Note that if you want your script to be interpreted by bash, each file should start with the line: #!/bin/bash and will have one (or more, as needed) commands following it. To execute each script in bash, so you can determine if it is working or...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If...

    Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If you could start the assignment and tell me how to do the rest it would be greatly appreciated! (Quick thumbs up answer response if thorough and correct) Maintain automobile records in a database Write a shell script to create, view and modify a simple database that contains automobile records. The shell script has to be done in Bourne shell syntax (bash as a matter...

  • Explain everything that is happening on line 125 of the script, where the roff2pdf() function is called. (Hint: sort out the function arguments and input/output redirection.) line 125: roff2pdf "$...

    Explain everything that is happening on line 125 of the script, where the roff2pdf() function is called. (Hint: sort out the function arguments and input/output redirection.) line 125: roff2pdf "$OUTPUT_TITLE" < $TMP_FILE_M > $OUTPUT_FILE #1 /bin/sh # Verify that the command line arguments are suitable if [ -z "$1" ] 11 [ $# -gt 2 ]; then echo "Usage: $0 <page> [<section>]" exit 1 1 # util is avail # Check whether a utility is available on the system. #...

  • 1. Write the command to set the following permissions on a script file with the following...

    1. Write the command to set the following permissions on a script file with the following name; myscript.sh Owner: full access; read, write and execute Group: read and execute Other: no access 2. Create a new file with the name "myfirstscript.sh". Write a new script that performs the following tasks in sequence; Display the usernames of currently logged in users; sorted from a-z HINT: You will need to filter the output of the whocommand Display a list of usernames who...

  • Ensure the following compiles 5. Variable scope (1 mark) Some variables are only accessible while executing...

    Ensure the following compiles 5. Variable scope (1 mark) Some variables are only accessible while executing specific code. Global variables are often thought of as evil because the state of a system can be altered making functions execute differently when it isn't expected. There is also the issue of block scope. For an example of block scope, see the file below. Notice that you don't get an error because the code uses the correct syntax. Although the syntax is correct,...

  • Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in...

    Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1)        a.) [1, 2, 2, 2]        b.) [1, 1, 1, 2]        c.) [1, 2, 1, 2]        d.) [1,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT