Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!