I have a large nested file structure; navigating from one working folder to the next requires verbose commands like cd ../../../../path/to/working/file
. Fortunately, the files are consistently named: part01_Part01-04.fileName/src/main/
To make navigation easier, I've written a Python script that takes the current directory name and increments or decrements the part
numbers according to command line args. The script prints an absolute filepath and then exits.
The Python script is called by a small Zsh function I wrote into my .zshrc, as follows:
function funcName () { builtin cd "$(/path/to/pythonExecutable $PWD $1)"; pwd; ls; }
Despite being a bit hacky, it works beautifully, as intended. My question has to do with the way it works: in order to have it work, I need to print the path string at the end of my Python script, as opposed to returning the path string. This was surprising and unexpected.
As I understand it, the return
statement should deliver my string to whatever called the script, whereas print
sends its cargo to stdout
. My Zsh function is not stdout. Can anyone tell me why it is working this way, and/or point me to any resources to help me flesh out what's going on under the hood?
Last, I'm sure there are cleaner ways of doing this in shell script alone, but I know Python, and don't know shell (yet). One step at a time.