Shell脚本错误:没有这样的文件或目录

时间:2022-05-26 02:22:02

I am trying to run a shell script file from my USB drive which has to run an executable. I got this tree:

我试图从我的USB驱动器运行一个shell脚本文件,该文件必须运行可执行文件。我有这棵树:

USBROOT/
    script.sh
    exe/
        myExe.exe
        Data/
            {Several Images}
        Results/
            {Results to be saved}

My .sh file looks like this(sorry, there is some french in the code :p):

我的.sh文件看起来像这样(对不起,代码中有一些法语:p):

#!/bin/sh
data="/exe/Data/"
exe="/exe/TopHat.exe"
rep_sortie="/exe/Results/"
fichier_sortie="GPU_Vivante_iMx6_linux.txt"
#
echo "Temps d'exécution du TopHat en secondes" >> $fichier_sortie
echo "Erosion G, Erosion L, Dilatation G, Dilatation L, Reconstruction V, Reconstruction AV, DT" >> $fichier_sortie
#
list_image=`ls ${data}U1*.jpg`
#
for f in $list_image 
do
image=${f##*/} 
#echo $image >> $fichier_sortie
$exe $f ${rep_sortie}${image} >> $fichier_sortie
done
#
list_image=`ls ${data}U2*.jpg`
#
for f in $list_image
do
image=${f##*/} 
#echo $image >> $fichier_sortie
$exe $f ${rep_sortie}${image} >> $fichier_sortie
done

But when I'm running it with the command line

但是当我用命令行运行它时

sh script.sh

from the USBROOT directory I got a "No such file or directory" error. After several tries, I think my problem start when I declare my variables 'data' and 'rep_sortie'. Do you know what I am doing wrong ? I dont understand why it cannot see this directory.

从USBROOT目录我得到一个“没有这样的文件或目录”错误。经过几次尝试,我认为当我声明我的变量'data'和'rep_sortie'时我的问题就开始了。你知道我做错了什么吗?我不明白为什么它看不到这个目录。

I checked that I have the correct end of line LF.

我检查了我有正确的LF行尾。

Baptiste

巴蒂斯特

1 个解决方案

#1


1  

/exe/Data/ will search for the folder named under root location of linux filesystem ("/"), i.e. where all the folders like root, home, usr, tmp and mnt are placed. And script will not find any folder with name of "exe" it will report the error u got.Always if in a path / is prefixed, it translates to root of Linux filesystem.

/ exe / Data /将搜索在linux filesystem(“/”)的根位置下命名的文件夹,即放置所有文件夹,如root,home,usr,tmp和mnt。并且脚本找不到任何名为“exe”的文件夹,它会报告你得到的错误。总是如果在路径/前缀中,它会转换为Linux文件系统的根目录。

There is difference between "/exe/Data"(Absolute path) and "./exe/Data"(Relative Path). I suppose later one is needed according to your requirement. AS:

“/ exe / Data”(绝对路径)和“./exe/Data”(相对路径)之间存在差异。我想以后根据你的要求需要一个。如:

./exe/Data will translate to ${PWD}/exe/Data which will surely not same as /exe/Data. where $PWD will prefix the present working directory.

./exe/Data将转换为$ {PWD} / exe / Data,这肯定与/ exe / Data不一样。其中$ PWD将在当前工作目录的前面。

Same modifications shall be made for /exe/TopHat.exe and other locations.

应对/exe/TopHat.exe和其他位置进行相同的修改。

#1


1  

/exe/Data/ will search for the folder named under root location of linux filesystem ("/"), i.e. where all the folders like root, home, usr, tmp and mnt are placed. And script will not find any folder with name of "exe" it will report the error u got.Always if in a path / is prefixed, it translates to root of Linux filesystem.

/ exe / Data /将搜索在linux filesystem(“/”)的根位置下命名的文件夹,即放置所有文件夹,如root,home,usr,tmp和mnt。并且脚本找不到任何名为“exe”的文件夹,它会报告你得到的错误。总是如果在路径/前缀中,它会转换为Linux文件系统的根目录。

There is difference between "/exe/Data"(Absolute path) and "./exe/Data"(Relative Path). I suppose later one is needed according to your requirement. AS:

“/ exe / Data”(绝对路径)和“./exe/Data”(相对路径)之间存在差异。我想以后根据你的要求需要一个。如:

./exe/Data will translate to ${PWD}/exe/Data which will surely not same as /exe/Data. where $PWD will prefix the present working directory.

./exe/Data将转换为$ {PWD} / exe / Data,这肯定与/ exe / Data不一样。其中$ PWD将在当前工作目录的前面。

Same modifications shall be made for /exe/TopHat.exe and other locations.

应对/exe/TopHat.exe和其他位置进行相同的修改。