/bin/sh sh -c cmd和cmd的区别
时间: 2024-01-17 21:05:12 浏览: 161
"/bin/sh sh -c cmd" 和 "cmd" 之间的区别在于,前者会在一个新的 shell 中执行 "cmd" 命令,而后者则是在当前 shell 中直接执行 "cmd" 命令。
具体来说,"/bin/sh sh -c cmd" 会启动一个新的 shell 进程,然后在这个新的 shell 中执行 "cmd" 命令。这个新的 shell 会继承当前 shell 的环境变量和配置,但是会创建一个新的进程来执行 "cmd" 命令。执行完 "cmd" 命令后,新的 shell 进程就会退出,控制权返回到原来的 shell。
而 "cmd" 则是直接在当前 shell 中执行指定的命令。这个命令会继承当前 shell 的环境变量和配置,并且不会创建新的进程。
因此,如果你需要在一个新的环境中执行命令,或者需要保护当前 shell 的环境变量和配置,可以使用 "/bin/sh sh -c cmd"。如果你只需要在当前 shell 中执行命令,就可以直接使用 "cmd"。
相关问题
sh experiments/COCOA/pcnet_m/train.sh Traceback (most recent call last): File "main.py", line 48, in <module> main(args) File "main.py", line 14, in main config = yaml.load(f) TypeError: load() missing 1 required positional argument: 'Loader' Traceback (most recent call last): File "/home/bai/anaconda3/envs/deocclusion/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/home/bai/anaconda3/envs/deocclusion/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/bai/anaconda3/envs/deocclusion/lib/python3.7/site-packages/torch/distributed/launch.py", line 263, in <module> main() File "/home/bai/anaconda3/envs/deocclusion/lib/python3.7/site-packages/torch/distributed/launch.py", line 259, in main cmd=cmd) subprocess.CalledProcessError: Command '['/home/bai/anaconda3/envs/deocclusion/bin/python', '-u', 'main.py', '--local_rank=0', '--config', 'experiments/COCOA/pcnet_m/config.yaml', '--launcher', 'pytorch']' returned non-zero exit status 1. 报的这个错该怎么解决
这个错误是由于在加载配置文件时出现问题导致的。可能的解决方案是使用正确的 YAML 加载器来加载配置文件。您可以尝试将代码中的 `yaml.load(f)` 替换为 `yaml.load(f, Loader=yaml.Loader)`。
修改后的代码如下所示:
```python
config = yaml.load(f, Loader=yaml.Loader)
```
这样应该可以解决 `TypeError: load() missing 1 required positional argument: 'Loader'` 错误。请尝试并查看是否解决了问题。
报错/bin/sh:apt-get comand not found
这个错误提示表明在您的 Dockerfile 中无法找到 `apt-get` 命令。这可能是因为您的基础镜像不包含 `apt-get` 工具。
请尝试使用适合您的基础镜像的正确的包管理工具命令。例如,如果您使用的是基于 Alpine Linux 的镜像,则可以使用 `apk` 包管理工具。
以下是一个示例,假设您使用的是基于 Alpine Linux 的镜像,并且要安装 Python 3.7 和其他依赖项:
```Dockerfile
# 使用基础镜像
FROM python:3.7-alpine
# 安装依赖项
RUN apk update && apk add --no-cache \
python3-dev \
build-base \
git \
cmake \
opencv-dev \
yaml-dev \
boost-dev \
protobuf-dev \
protobuf-compiler
# 安装 Torch GPU 版本 1.10.1
RUN python3.7 -m pip install torch==1.10.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html
# 克隆您的项目代码库
RUN git clone <your_project_repository> /app
# 设置工作目录
WORKDIR /app
# 安装其他依赖项
COPY requirements.txt /app
RUN python3.7 -m pip install -r requirements.txt
# 定义默认命令
CMD ["python3.7", "your_script.py"]
```
请将 `<your_project_repository>` 替换为您的项目代码库的实际 URL。
根据您使用的基础镜像,您可能需要调整安装依赖项的命令。请查看基础镜像的文档,以了解正确的包管理工具和命令。
保存并关闭 Dockerfile 文件后,使用以下命令构建 Docker 镜像:
```bash
docker build -t your_image_name .
```
其中,`your_image_name` 是您为镜像指定的名称。
希望这能帮助到您!如果您有任何其他问题,请随时问我。
阅读全文
相关推荐
















