How to simulate dos "CD .." in a small c-shell for linux

This is for my small project, I am trying to set the current working directory of the process to one directory up, as if my current directory .. \ downloads \ movies I would like the code to set the directory .. \ downloads

I know that this is possible by getting the current path to the working directory and extracting from it the path of the directory that I need, and then run chdir (), however this code should be as efficient and easy as possible, and I find the method to be cumbersome above .

Thanks in advance falks.

+3
source share
2 answers

How simple and effective are you? Sort of

if (chdir("..") < 0)
{
    perror("chdir");
    exit(1);
}
+4
source

U can try to do something like this

chdir("..");

!:)

+4

Source: https://habr.com/ru/post/1736211/


All Articles