I am currently doing the MIT missing semester lecture 2.
Exercise number 2 has us write functions marco.sh and polo.sh to "polo" back to the directory where marco was executed. I wrote two simple scripts for this, but polo.sh does not cd
into the directory I saved.
marco
#!/bin/bash
currentDirectory=$(pwd)
echo "current directory is $currentDirectory"
echo "$currentDirectory" > /tmp/missing/marcoDirectory.txt
(it was necessary to save the directory in an .txt file because bash wouldn't recognize the currentDirectory variable with polo. Again, this is an exercise, I'm not super proud of it)
polo
#!/bin/bash
next=$(cat /tmp/missing/marcoDirectory.txt)
echo "changing directory to $next"
cd $next
The fact is that the command cd
does not seem to recognize that it has to be executed. If I try to cd
somewhere else, it also fails.
How should I approach solving the cd
issue?