56.9k views
2 votes
add a new built-in path command that allows users to show the current pathname list, append one pathname, or remove one pathname. in your shell implementation, you may keep a data structure to deal with the pathname list. if you do not use execle() or execve() that allows you to execute with your own environment variables, you will need to add it to the "real" path environment variable for executables in the path to work correctly. the initial value of path within your shell shall be the

User Aditya
by
5.5k points

1 Answer

0 votes

Answer:

#include<stdio.h>

#include <stdlib.h>

#include <unistd.h>

void path() {

char path[100];

if (getcwd(path, sizeof(path)) != NULL) {

printf("path: %s\\", path);

} else {

perror("getcwd() error");

}

}

void addPath(char *a) {

char path[100];

if (getcwd(path, sizeof(path)) != NULL) {

printf("path: %s %s\\", path,a);

} else {

perror("getcwd() error");

}

}

void removePath(char *a) {

char path[100];

if (getcwd(path, sizeof(path)) != NULL) {

int len = (strlen(path)-strlen(a));

printf("(%.*s)\\", len, path);

} else {

perror("getcwd() error");

}

}

int main()

{

char userInput[100] =" ";

char userInput2[100 ]= " ";

printf("Current Path");

path();

printf("Enter Path to be added\\");

scanf("%s", &userInput);

addPath(userInput);

printf("Enter Path to be removed\\");

scanf("%s", &userInput2);

removePath(userInput2);

return 0;

}

User BarbaraKwarc
by
6.4k points