我编写了一个bash脚本,该脚本根据输入参数获取三个路径,然后在该路径中获取图像名/文件名.
I have written a bash script that gets three paths based on input parameters and then then gets the imagename/filename in the path.
类似的东西: 我提供:
Something like: I provide:
AA=/home/user然后使用find命令获取 /home/user/dir2/images/dir/tellmeimage1fun.bin
Then it uses the find command to get /home/user/dir2/images/dir/tellmeimage1fun.bin
最后,我必须将tellmeimage1fun.bin作为输出.
Finally I have to get tellmeimage1fun.bin as output.
脚本:
#!/bin/bash echo "arg0 n/k/d" AA=$1 CC=$3 PATH1="`find $AA/dir2/images/dir/ -name *image1*.bin`" PATH2="`find $AA/dir2/images/dir/ -name *bimage2*.bin`" PATH3="`find $AA/dir2/images/dir/ -name *cimage3*.bin`" if [ $CC = "n" ] ; then PATH=$PATH1 elif [ $CC = "k" ] ; then PATH=$PATH2 else PATH=$PATH3 fi #Getting filename name from path: IMG="`ls $PATH | cut -d "/" -f6`" OUTPUT: /users/prasapat/bin/sl5: line 22: ls: command not found /users/prasapat/bin/sl5: line 22: cut: command not found如果我给出了ls的完整路径并削减了它们的工作范围.但是我不想对脚本中的所有命令执行此操作.如果我删除最后一行并回显PATH变量,那是完全可以的.仅在添加了最后一条命令后,我才看到问题所在.
If I give complete paths to ls and cut they work. But i don't want to do that for all commands in the script. If i remove the last line and echo the PATH variable it is completely fine. Only after adding the last command, I see the problem.
我做错了什么?
推荐答案问题是,如果调用时未使用完整路径,则您将重新定义PATH变量,bash将在其中查找二进制文件.
The problem is that you are redefining the PATH variable where bash looks into to find the binary files if you don't use a complete path when calling.
您应该将bash脚本中的PATH更改为MYPATH或类似的名称,以免与已经存在的环境变量混淆.
You should change the PATH in your bash script to MYPATH or something like that, so that it doesn't mess with the already environmental variables.
如果您不知道PATH变量是什么,可以查看维基百科的文章
If you don't know what the PATH variable is for you can look at wikipedia's article
更多推荐
得到“找不到命令". bash脚本中的错误
发布评论