Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

How would I 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. I don't want to use use the Unix which command, the ksh whence (type) command, or the bash type command.

The script should find only the first occurrence of the "file". If the file is not found, the script should print an error message that the file was not found in the user's path. (Both the filename and the users path should be printed.)
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.

I also don't want to use temporary files.

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. Otherwise, each directory in the path is searched for an executable file.
usage: mywhich [-a] command ....

For example:

prompt> mywhich ls
/bin/ls

prompt> mywhich -a cc
/bin/cc
/usr/ucb/cc

prompt> mywhich ./mywhich
./mywhich

prompt> mywhich fooblar
fooblar not found

prompt> mywhich ksh sh csh bash
/usr/bin/ksh
/bin/sh
/bin/csh
/usr/local/bin/bash

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9211984

Have any Question?


Related Questions in Computer Engineering

The glen arboretum wants to start removing invasive norway

The Glen arboretum wants to start removing invasive Norway Maple trees. To determine just how bad the problem is you set up five plots that are three meters on each side. You find that your plots have 2, 5, 9, 1, and 3 N ...

A random sample ofnbsp77nbspeighth gradenbspstudents scores

A random sample of 77 eighth grade? students' scores on a national mathematics assessment test has a mean score of 285. This test result prompts a state school administrator to declare that the mean score for the? state' ...

At a certain temp the kp for the decomposition of h2s is

At a certain temp, the Kp for the decomposition of H2S is .883. H2S (g) ----> H2(g) + S (g) Initially, only H2S is present at a pressure of  .181 atm  in a closed container. What is the total pressure in the container at ...

Strengths and weaknesses of university that attracts and

Strengths and Weaknesses of University that attracts and distracts students from joining that university with respect to the theory of planned behaviour

Answer the following question a suppose you have two

Answer the following Question : (a) Suppose you have two initially empty queues Q1 and Q2. Explain how you could implement the stack ADT using Q1 and Q2. Your answer should provide pseudocode algorithms for the stack ope ...

Question using the apple company identify all the social

Question: Using the Apple company, identify all the social media platforms it currently uses. List all the social media platforms. List five different KPI's you could use to measure the engagement on each platform. Expla ...

Why are standards needed in data communication and

Why are standards needed in data communication and networking? What are the advantages and disadvantages of standards? How do standards fit in with regulations at the federal, manufacturing, and organizational levels? Gi ...

Question when a syscall is called which register must have

Question : When a syscall is called which register must have the syscall number? Which syscall is a must for every program? Why?

Question a small financial focused business is looking to

Question : A small, financial focused business is looking to organize and secure its network. It currently has a single public IP address from a local telecom. Construct an argument as to how you think a company should e ...

Briefly explain the meaning of the t-test for regression

Briefly explain the meaning of the t-test for regression analysis. How can the "rule of two" be used to evaluate t-ratios?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As