Write a shell script to locate executable files

Assignment Help Operating System
Reference no: EM131695373

Assignment

The example output in the links above show the results of a program run through a series of tests. The examples show what the PATH environment variable was set to for the test case, the command that was run, the expected results and the output of the program.

PATH   ==> /usr/bin:/usr/local/bin:/usr/bin/X11

RAN    ==> mar1.sh -a tar

RESULT ==> PASSED

EXPECTED RESULT ==> /usr/bin/tar

PROGRAM OUTPUT  ==> /usr/bin/tar

You script will should out put the results (the data after the ==> in the EXPECTED RESULT) section.

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

<command> NOT FOUND

<command> 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>mywhichfooblar
fooblar not found

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

The PDF file (in the folder that says Assignment 1 example pdf) has a flow chart example of how to program Assignment 1.

Here is some psuedo code:

BEGIN 
    set FINDALL to false
    IF $1 equals -a THEN
        set FINDALL to TRUE
        dispose of $1
    END-IF
    FOR each Positional Parameter ($file) DO
        IF $file is a pathname THEN
            IF if $file is executable and not a directory THEN
                echo $file
            ELSE
                echo $file  is NOT Found
            END-IF
        ELSE
            set FOUND to false
            # Don't forget to handle the special cases of PATH
            FOR  P in PATH (: separated list) DO
                IF $P/$file is executable and not a directory THEN
                    set FOUND to true
                    echo $P/$file
                    IF FINDALL is FALSE THEN
                        BREAK FROMTHE for  LOOP
                    END-IF
                ELSE
                END-IF
                IF FOUND is FALSE THEN
                    echo $file is NOT FOUND
                END-IF
            END-FOR
        END-IF
    END-FOR
END

Reference no: EM131695373

Questions Cloud

Perfectly competitive environment : If this firm is operating in a perfectly competitive environment and is a price-taker, what would their total profits be if the market price was $30.9?
Identify which make islam a tougher sell in many cultures : What cultural issues can you identify which make Islam a tougher sell in many cultures - especially Western ones
How much of her gain is taxed : Assuming Jeanie is in the highest tax bracket for ordinary income and the Medicare surtax applies, how much of her gain is taxed at 28.8 percent
What would be the quantity of net exports in country a : If there is free trade between these two countries, what would be the quantity of Net Exports in Country A?
Write a shell script to locate executable files : 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.
Relationship in unit serviced and average direct labor hours : The only remaining decision is the standard for labor usage. To assist in developing this standard, the engineering department has estimated the following.
Domestic production of cars : Suppose a tariff of $3800 per unit is place on cars. As a result, domestic production of cars increases from 54,000 cars per year to 81,000 cars per year
Discuss what is your overall impression of kwanza : Indigenous religions generally are characterized by three basic patterns
Area of the deadweight loss : If a price ceiling of $11.42 is imposed, what will be the area of the deadweight loss?

Reviews

Write a Review

Operating System Questions & Answers

  Question about big oh relationship

Provide witnesses n0 and c that can be used to prove the relationship. Select your witnesses to be minimal, in the sense that n0-1 and c are not witnesses, and if d

  A system uses a page size

A system uses a page size of the 4 Kbytes and a program size of 46 kbytes is allocated memory. what is the fragmentation?

  How to implement a priority-based scheduler for xv6

COP4610: Introduction to Operating Systems Project: Priority-based Scheduler for Xv6. In this assignment, you will learn how to implement a priority-based scheduler for xv6. To get started, download a new copy of the xv6 source code from here. Do N..

  Implementation of the electronic medical record

Explain how the effectiveness the implementation of the electronic medical record change will be determined once implemented.

  Create a makefile called makefile

Create a makefile called Makefile based on all the .cpp files in the current directory

  Compute the speedup for options and decide the option proces

Compute the speedup for options and decide the option Processor Y should take.

  Square and multiply and generators

Show that a is a generator for p if and only if a(p-1)/qi mod p ≠ 1 for all i = 1, 2, ... , n. Use this test to determine if 3 is a generator for p = 11.

  Identify and describe the processes involved in the

identify and describe the processes involved in the management of the services disk quotas and security of both windows

  What is policy used in os to prevent deadlock and starvation

What is the policy used in OS to prevent deadlock and starvation? What is the difference between a static IP and a dynamic IP?

  What is meant by user time in terms of cpu usage

What is the size of the cache on your CPU? What is meant by "User Time" in terms of CPU usage? What is meant by "Kernel" or "System" time in terms of CPU usage?

  Process scheduling simulation of round robin program

Process Scheduling simulation of Round Robin program implementation in C language

  Install a wireless lan network in an organization

Discuss and explain reasons that might make it favorable or unfavorable to install a Wireless LAN network in an organization over a traditional wired network.

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