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

  Implementation of algorithms for process management

The Shortest Job Next (SJN) algorithm queues processes in a way that the ones that use the shortest CPU cycle will be selected for running rst.

  Develop a user mode command interpreter

Develop a user mode command interpreter which support list-short.

  Memory allocation in operating system

Analysis and implementation of algorithms for memory allocation in operating system, Explain First- t and best- t methods are used in memory allocation in operating systems.

  Stand alone child process

Forking the child process

  Write a multi-threaded program

Write a multi-threaded program to solve producer and consumer problem

  Marginal and average cost curves

n a competitive market place (pure competition) is it possible to continually sell your product at a price above the average cost of production.

  Simulating operating systems scheduling

Simulate the long-term scheduler, the short-term scheduler and the I/O scheduler of the computer using the First-Come-First-Serve algorithm.

  Issues with trusted platform module

Research paper discussing the issues with Trusted Platform Module (TPM)

  Threads

Explain a complication that concurrent processing adds to an operating system.

  Design and programming

Use the semaphore methods to control the concurrency of the solution

  Virtual machines

Virtual machines supported by a host operating system

  Discuss an application that benefits barrier synchronization

Discuss an application that would benefit from the use of barrier synchronization

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