bash - 在google colab中执行shell文件时没有这样的文件或目录
问题描述
我在 google colab 中运行机器翻译代码,因为我将代码克隆到我的驱动器中,并将驱动器位置存储在一个变量中:
!PATH='/content/mydrive/My Drive/facebook/unsup'
克隆在所需位置成功完成。当我尝试运行 shell 文件时出现问题:
!."$PATH/NMT/get_data_enfr.sh"
它返回
/bin/bash: ./content/mydrive/My Drive/facebook/unsup/NMT/get_data_enfr.sh: No such file or directory
但如果我跑
!head "$PATH/NMT/get_data_enfr.sh"
它显示文件内容。
# Copyright (c) 2018-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
set -e
#
解决方案
您可以尝试将脚本运行为:
sh "$PATH/NMT/get_data_enfr.sh"
在像上面那样运行它之前,请运行以下命令:
chmod +x "$PATH/NMT/get_data_enfr.sh"
似乎@dash-o 是正确的,当您在脚本.
前面运行脚本时,它实际上是从当前目录中寻找脚本。
它适用于head
命令,因为完整路径正在传递给它,head
并且它正在该路径中找到文件,但在运行它时不是真的。
./path/to/script
实际上试图从当前目录运行脚本并忽略绝对路径。但是当使用sh
and then时$PATH
,它实际上是从绝对路径运行的。
推荐阅读
- python - MongoDB 使用同一个文档更新整个集合
- android - 创建餐厅/酒吧菜单应用程序的最佳解决方案
- excel - 计算年化平均回报
- ios - Xcode SpriteKit 游戏 - 如何在应用安装期间为多种屏幕尺寸配置 UI
- php - 内存泄漏 - 一个简单的 phpinfo() 页面会增加容器内存使用量
- android - 检查互联网
- javascript - React Native 条件渲染自定义卡片样式问题
- selenoid - 无法使用 docker 启动 selenoid 服务器
- javascript - Nodejs docx-merger 插件“Word 发现不可读的内容”
- react-native - 根据语言选择重新渲染当前视图