Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am writing my own shell in c. I have to write a built-in command called path which adds to the search path of the

I am writing my own shell in c.

I have to write a built-in command called "path" which adds to the search path of the shell.

With this, the user can specify a path variable to describe the set of directories to search for executables.

The path command takes 0 or more arguments, with each argument separated by whitespace from the others.

A typical usage would be like this: mysh> path /bin /usr/bin, which would add /bin and /usr/bin to the search path of the shell. If the user sets path to be empty, then the shell should not be able to run any programs (except built-in commands or commands specified with full or relative paths). The path command always overwrites the old path with the newly specified path.

I have a char** tokens, which tokenizes user input. So if the user enters path /bin /usr/bin then tokens[0] = path, tokens[1] = /bin, and tokens[2] = /usr/bin, and tokens[3] = NULL. I need to use this information to create a new array so that the variable path consists of path[0] = /bin, path[1] = /usr/bin, path[2] = NULL.

I think path will be a char**.

Also, I've been using dynamic memory allocation.

Ultimately, after using this path command, a user should be able to type something like the ls command on its own without having to type /bin/ls or /usr/bin/ls.

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

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions