Java项目执行bash脚本遇两类“No such file or directory”错误求助
Hey there, let's fix this step by step—no terminal expertise required, I'll keep it clear!
先搞懂两个报错的原因
1. 为什么去掉点会提示文件找不到?
When you changed the path to /runtime/updatemcp.py, that's an absolute path—it tells the system to look for a runtime folder directly in your system's root directory (/), not the folder you're currently in. That's why it can't find the file, even though runtime is right there with you. You need to keep the relative path: either ./runtime/updatemcp.py (the dot means "current directory") or just runtime/updatemcp.py (both work the same here).
2. 为什么保留点会提示python2: No such file or directory?
Your script is trying to run the Python 2 interpreter, but your system doesn't have it installed, or it's not available under the python2 command. Most modern systems default to Python 3 now, so we need to fix this part.
具体解决方法
Pick one of these options based on what works for your setup:
Option 1: Install Python 2 (if the script requires it)
If the updatemcp.py script only works with Python 2, install it via your system's package manager:
- Ubuntu/Debian: Open terminal and run
sudo apt update && sudo apt install python2 - Mac (with Homebrew): Run
brew install python@2
Once installed, run your script again: bash updatemcp.sh—it should find Python 2 now.
Option 2: Modify the script to use Python 3 (if the script is compatible)
If updatemcp.py works with Python 3 (many old scripts do now), edit your updatemcp.sh script:
- Open the script in a text editor (like
nano updatemcp.shin terminal) - Change the second line to:
python3 ./runtime/updatemcp.py "$@" - Save and exit (in nano, press
Ctrl+O, thenEnter, thenCtrl+X)
Now run the script again—it'll use Python 3 instead of looking for Python 2.
Option 3: Create a soft link for Python 2 (if you already have it but it's named differently)
If you have Python 2 installed but it's called something like python2.7 instead of python2, create a link so the system recognizes the python2 command:
Run sudo ln -s /usr/bin/python2.7 /usr/local/bin/python2 (replace /usr/bin/python2.7 with the actual path to your Python 2 executable if it's different).
Quick checks to confirm everything's in place
Before running the script again, verify these to avoid extra headaches:
- Make sure you're in the right folder: Run
lsand you should seeupdatemcp.shand theruntimefolder listed. - Confirm
updatemcp.pyexists: Runls runtimeand check for the file. - Verify your Python setup: Run
python2 --version(if you installed it) orpython3 --versionto make sure the interpreter is working.
内容的提问来源于stack exchange,提问作者Miloertas

