$ type cd
cd is a shell builtinHow does `cd` work?
11–20 of 93 posts
Re: How does `cd` work?
#12I tried to create a command line tool that mimics some behavior of a bookmark manager in the terminal. https://github.com/serv/lbm Unfortunately, I learned that there's is no way to invoke cd programmatically from a program, but I didn't get an explanation I could understand why this is not possible. Can someone explain why you can't invoke cd from a program?
cd is part of your shell, so trying to invoke cd from another program would be like opening a new browser tab from another program. It's an internal feature without an outward-facing API.
Re: How does `cd` work?
#13I tried to create a command line tool that mimics some behavior of a bookmark manager in the terminal. https://github.com/serv/lbm Unfortunately, I learned that there's is no way to invoke cd programmatically from a program, but I didn't get an explanation I could understand why this is not possible. Can someone explain why you can't invoke cd from a program?
As far as I know, you will need to provide the user with an alias or a function or something that can put in their .bashrc or something, and there is no other way to do it. (Anything that could would constitute a violation of the UNIX process model.)
Re: How does `cd` work?
#14Re: How does `cd` work?
#15Here's cd implemented as a stand-alone program: https://github.com/robertswiecki/extcd
To control the shell process.
Re: How does `cd` work?
#16Random piece of info about cd: cd.. (no space between "cd" and "..") works on Windows
You can simulate that behavior on bash with an alias such as this one:
alias cd..="cd .."Re: How does `cd` work?
#17Random piece of info about cd: cd.. (no space between "cd" and "..") works on Windows
Re: How does `cd` work?
#18Here's cd implemented as a stand-alone program: https://github.com/robertswiecki/extcd
Re: How does `cd` work?
#19I tried to create a command line tool that mimics some behavior of a bookmark manager in the terminal. https://github.com/serv/lbm Unfortunately, I learned that there's is no way to invoke cd programmatically from a program, but I didn't get an explanation I could understand why this is not possible. Can someone explain why you can't invoke cd from a program?
You can't change another process's internal state without sending a message that the other process can choose to interpret (or by hacking the memory that the process is using)
Re: How does `cd` work?
#20Earlier quoted context omitted.
cd is part of your shell, so trying to invoke cd from another program would be like opening a new browser tab from another program. It's an internal feature without an outward-facing API.
There's no reason why one shouldn't be able to invoke the chdir system call and implement the same behaviour.