Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For Linux - Please replace the XXXs in the script below to solve this: Write a shell script that accepts exactly 1 argument which must

For Linux - Please replace the XXXs in the script below to solve this:

Write a shell script that accepts exactly 1 argument which must be a positive

integer. The script will print a comma separated list of integers, all on the same

line, starting with the entered value and decreasing to 1.

The last printed value should not be followed by a comma.

The script should also be able to handle the following error situations:

o incorrect number of arguments

o non-positive arguments (dont worry about trying to handle non-integer

arguments)

The script file name must be: printnum.sh

The script must be located in $HOME/itec400/homework

Make sure the permissions on the your itec400 directory are 705

Make sure the permissions on your script are 705

Printnum.sh script logic:

#!/bin/ksh

# Script name: printnum.sh

# Execute script: ./printnum.sh

# Verify the number of arguments and exit if not equal to 1

if [ $# XXX 1 ]

then

XXXXXX "error: program must be executed with 1 argument "

printf "usage: $0 value (where value >= 1) "

exit 1

fi

# Verify argument is a positive number

XX [ $1 -lt 1 ]

XXXX

printf "error: argument must be a positive number "

printf "usage: $0 value (where value >= 1) "

exit 1

XX

# Store command line argument in variable i

i="$1"

# Loop and print $i while decrementing variable to =1 (with comma)

XXXXX [ XX -gt 1 ]

do

printf "$i, "

i=$(($i - 1))

done

# Print the last digit without a comma

XXXXXX "$i "

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

4. What action should Cherita Howard take and why?

Answered: 1 week ago