Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ex. 3 Defining functions in shell(4 Points) In this exercise, you will update the script showusr that is given to you (you can use vi

image text in transcribed

Ex. 3 Defining functions in shell(4 Points) In this exercise, you will update the script showusr that is given to you (you can use vi to edit this file), to write a function fname, that accepts a userid (such as your socs unix account) as the argument and sets an environment variable FNAME with the value that is the first name of the userid (explore the pinky command to get the first name of the userid). The function will also return an integer code to indicate its status (see examples below). Do not use the exit command in the function ! 1.(1 Point) For properly commenting throughout the source code. 2.(1 Point) If fname is not passed an argument, set the variable FNAME to ERROR and return a value of 1. Below is an example of me "loading" the function to shell environment and then executing it (with no argument). I am using the echo command to check the return code as well as the value stored in FNAME. $ . showusr $ fname $ echo $?$FNAME 1 ERROR 3.(1 Point) if the argument passed to fname cannot be found among the sessions logged in, it should set FNAME to NOTFOUND and return 0. $ fname nosuchid $ echo $? $FNAME O NOTFOUND 4.(1 Point) if the userid passed as argument to fname is found among the sessions logged in, it should set FNAME to the first name of that user and return 0. $ fname jdsilv2 $ echo $?$FNAME O Joseph Ex. 3 Defining functions in shell(4 Points) In this exercise, you will update the script showusr that is given to you (you can use vi to edit this file), to write a function fname, that accepts a userid (such as your socs unix account) as the argument and sets an environment variable FNAME with the value that is the first name of the userid (explore the pinky command to get the first name of the userid). The function will also return an integer code to indicate its status (see examples below). Do not use the exit command in the function ! 1.(1 Point) For properly commenting throughout the source code. 2.(1 Point) If fname is not passed an argument, set the variable FNAME to ERROR and return a value of 1. Below is an example of me "loading" the function to shell environment and then executing it (with no argument). I am using the echo command to check the return code as well as the value stored in FNAME. $ . showusr $ fname $ echo $?$FNAME 1 ERROR 3.(1 Point) if the argument passed to fname cannot be found among the sessions logged in, it should set FNAME to NOTFOUND and return 0. $ fname nosuchid $ echo $? $FNAME O NOTFOUND 4.(1 Point) if the userid passed as argument to fname is found among the sessions logged in, it should set FNAME to the first name of that user and return 0. $ fname jdsilv2 $ echo $?$FNAME O Joseph

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

Students also viewed these Databases questions