Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a shell script to locate executable files. This script takes a list of file names from the command line and determines which would be

Write a shell script to locate executable files. This script takes a list of file names from the command line and determines which would be executed had these names been given as commands.

The search path should be based only on the user's PATH environment variable. You shall not use the Unix which command, the ksh whence (type) command, the locate command, or the bash type command.

The code for the script shall not use the UNIX ls command to determine if the file is executable or if it exists.

The script should find only the first occurrence of the "file". If the file is not found, the script the following

NOT FOUND

would be replaced by the name of the "file" you didn't find.

If the first parameter is '-a', then the script should print all occurrences of the executable file in the user's path. Again if the file was not on the path, an error message should be displayed.

The find command shall not be used.

A project using temporary files will not be graded.

Note: The shell variable PATH defines the search path for the directory containing the command. Alternative directory names are separated by a colon (:). The current directory can be specified by two or more adjacent colons, or by a colon at the beginning or end of the path list.

If the command name contains a / then the search path is not used, you just check if the command/file specified is executable and not a directory. Otherwise, each directory in the path is searched for an executable file.

usage: mywhich [-a] command ....

Examples: The locations of these programs may vary on different systems and the users PATH environment variable.

prompt> mywhich

ls /bin/ls

prompt> mywhich -a cc

/bin/cc

/usr/ucb/cc

prompt> mywhich ./mywhich

./mywhich

prompt> mywhich /bin/ls

/bin/ls

prompt> mywhich fooblar

fooblar not found

prompt> mywhich ksh sh csh bash

/usr/bin/ksh

/bin/sh

/bin/csh

/usr/local/bin/bash

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

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

Achieve a tone that connects with your audience and avoids bias

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago

Question

What is IUPAC system? Name organic compounds using IUPAC system.

Answered: 1 week ago

Question

What happens when carbonate and hydrogen react with carbonate?

Answered: 1 week ago