How would i write a shell script to locate executable files

Assignment Help Programming Languages
Reference no: EM13948117

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

Reference no: EM13948117

Questions Cloud

Digital transformation for the news paper industry systems : Demonstrate effective communication by composing writing that communicates ideas, meaning and/or argument in a format that broadly follows conventions in the information systems field.
The relatively homogeneous-enduring divisions in a society : Gordon Jones is considering purchasing a computer from Best Buy. He has created a scale for rating eight different computers on three different characteristics. He plans to short-list only those computers, that score at least a seven on his scale ..
Determining the fluorescence and phosphorescence : 1. (a) In your own words describe briefly the phenomenon of luminescence. (b) What is the distinction between fluorescence and phosphorescence?
Are all foods labeled natural in the same way : Do you think the food industry in general has equivocated on food labeling? Are all foods labeled natural in the same way? Has modern society subverted the concept of nature?
How would i write a shell script to locate executable files : 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.
Compute the mce for the given product : Compute the MCE for this product. Discuss how lean improvements can help improve this efficiency measure. Is this a lag or a lead measure? If lag, what would be some lead measures that would affect this measure?
Opacity and translucency in insulators : 1. Briefly explain what determines the characteristic color of (a) a metal and (b) a transparent nonmetal. 2. Briefly explain why some transparent materials appear colored while others are color- less.
The result is in the domain n : Find the truth set for the following predicates: Hint: answer should be a { set } A) 8/x where x is an integer,the result is in the domain N
Reflection losses of transparent materials : Briefly explain how reflection losses of transparent materials are minimized by thin surface coatings. The index of refraction of quartz is anisotropic. Suppose that visible light is passing from one grain to another of dif- ferent crystallographic..

Reviews

Write a Review

Programming Languages Questions & Answers

  Why is it significant to use systems analysis

"Why is it significant to use systems analysis and design methodologies when building system? Why not just build system in whatever way seems to be quick and easy?

  Correct mistakes on the command line

In this lab you will determine the shell that you are running, correct mistakes on the command line, and use filename generation. You will also learn about help that the system provides in the form of man pages, the --help option, and the bash hel..

  Program that asks for user-s age

Write a program that asks for user's age. Based on their response print "You can vote" (18 years old or older) or "You can't vote".

  Create an application to calculate sales persons salary

a salesperson who grosses $5000 in sales in a week receives $150 plus 10% of $5000, a total of $650. Write an application that calculate each sales person's total salary per week.

  Application where you ask the user to input the price

Write an application where you ask the user to input the price per letter (PPL), and then ask the user to input the sentence they want printed. The application should then calculate the number of letters and give the user the total cost in the follow..

  Program that calculate the average of a group of test scores

Write a program that calculate the average of a group of test scores, where the lowest score is dropped. It should use the following functions: void getScore() - should ask the user for a test score, store it in a reference parameter variable, and..

  Write function to receive two passed parameters single value

Write down the function which will receive as two passed parameters single precision value for product price and integer value for quantity.

  Identify why the two tests fail and correct the code

Your first task in this assignment is to study the given code, identify why the two tests fail, and correct the code.

  Create a c# console application project

Within the namespace and outside of the wrapper class for Main create a class named assignment8 that inherits from System.Windows.Forms.

  Implement shape hierarchy-compute area of two-dimensional

Implement Shape hierarchy. Each TwoDimensionalShape must contain function getArea to compute the area of two-dimensional shape. Each ThreeDimensionalShape must have member functions.

  What are tools and strategies to increase traffic website

Select a web site from an education industry (university, school or training center) and analyze the ease of use of at least 3 functions and/or features?

  Shows the graphic simulation of the elevator

The elevator could be called from level 2 by the external call button IP0 being pressed. The elevator doors should then close via OP3, once closed IP5 (doors closed sensor) should energise.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd