🤣🤣🤣 What am I? Suicidal?
Voted for printf, just to gratify my inner C snob (that doesn't actually know much C at all ^__^)
But I *do* use it occasionally in scripts and one-liners when I need nicely formatted output.
python3 -c 'import os; print(os.getenv("PWD"))' is the best option.
cat /proc/cwd
You can not trust ENVIRONMENT
There are issues with getenv(), putenv(), and setenv(). The semantics are not consistent and can be abused.
The pwd executable inherients the ENVIRONMEMT via fork() and execve() from the parent process.
If the enviroment variables have been corrupted already, then there could be turtles.
Most code does not call chdir() so using PWD probably did not change.
But, if the software in question creates addiitonal environment variables that point to subdirectories, there could be issues, especially if there are libraries involved that have not been vetted via source code review.
@nixCraft None of the above.
echo ${PWD}