得到“找不到命令". bash脚本中的错误

编程入门 行业动态 更新时间:2024-10-14 04:29:31
本文介绍了得到“找不到命令". bash脚本中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我编写了一个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脚本中的错误

本文发布于:2023-11-24 12:38:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625234.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   脚本   命令   错误   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!