0

I`m implementing pwd builtin in mini shell.

How could I get relative path without using environment variable "PWD"

(getenv("PWD"))

Example:

CWD = /tmp

getcwd("/tmp", buff, size)

returns absolute location => /private/tmp.

How can I get "/tmp" in order to print in?

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
  • 1
    I think the [man page for getcwd()](https://linux.die.net/man/3/getcwd) might be of interest to you. – Matthew P. Apr 29 '20 at 21:57
  • 2
    Can you please explain how `/tmp` and `/private/tmp` are related? Is one symlinked to the other? Or bind mounted? Or something else? – kaylum Apr 29 '20 at 22:03

1 Answers1

0

You can not do so.

When shell initialize, it stores current working directory to shell`s local variable. Shell gets cwd from getcwd() (if enviroment variable "PWD" is not set) and getenv("PWD") (if "PWD" is set) during the initialization.

Example: You are in /tmp (PWD=/tmp) (tmp = symbolic link)

CASE A

zsh

pwd

Result: /tmp

CASE B

env -i zsh

pwd

Result: /private/tmp

Community
  • 1
  • 1