admin 管理员组

文章数量: 1087652

bash运行.sh文件出现 command not found: XX某变量名

bash运行.sh文件出现 command not found: XX某变量名

bash或zsh运行 temp.sh

temp.sh
#!/bin/bash
export CUDA_VISIBLE_DEVICES=1
# compile pse
cd ./pse/
python setup.py build
cd ..
## run test
test_img_dir = "path/to/img/test"   # 【注意这里test_img_dir后面的空格】
test_single_img_path='/path/to/test/xx.jpg'
result_base="./results/"
net_file = "network_v3"   
net_arch="resnet18"python -u ./test.py \--test_single_img_path "${test_single_img_path}" \--test_img_dir "${test_img_dir}" \--result_base "${result_base}" \--net_file ${net_file} \--net_arch ${net_arch} \

出现错误

  • test.sh: line 19: /data00/shiwei.11/datasets/detData1/stamp/crop_images/test: Is a directory
  • test.sh:20: command not found: test_img_dir
  • test.sh:28: command not found: net_file

解决措施

其实这个问题很简单,在写xx.sh文件时,定义每个变量时,后面的“=”与变量名之间不要留空格,与后边的值之间也不要有空格,上边代码中删除test_img_dir和net_file后面的空格就好。

在window上写文件时,容易造成空格错误,没有高亮提醒。

本文标签: bash运行sh文件出现 command not found XX某变量名