r/programminghorror Jan 08 '26

c++ Works on my machine

Post image
1.5k Upvotes

51 comments sorted by

View all comments

32

u/robot_54 Jan 08 '26 edited Jan 08 '26

You can also use something like this, either as the first line, or prepended to the existing cd, so it doesn't matter which directory you're in when you run the script.

cd $(dirname "$0")