【问题标题】:ls: command not found BASH [duplicate]ls:找不到命令 BASH [重复]
【发布时间】:2017-02-23 01:01:46
【问题描述】:

此脚本尝试将文本文件复制到另一个目录。 我不明白为什么我会遇到这个问题: ./move_in.sh:第 36 行:ls:找不到命令 在我添加 if 语句之前它工作正常。

update_file=pwd
echo ""
echo "You can move a text file from your PC into the repository"
echo ""
echo "You need to know where is your text file"
cd /
ls
times=1
echo ""
echo "Where is your text file?"
read directory

while [ -d $directory ]
do
echo $times
if [ $times == 1 ]
then
LAST=$directory
fi

if [ $times != 1 ]
then
LAST=$PATH/$directory
fi

cd $directory
ls
echo ""
echo "Where is your text file?"
read directory
PATH=$LAST
echo $PATH
times=$((times + 1))
done

PATH=$PATH/$directory
echo $PATH
open $PATH
cp $PATH /\$update_file
echo "You found the text file!"
exit 0

我想在进程完成时获得文件的完整路径,这就是我使用 LAST 和 PATH 的原因,并且我将它们均衡化。

【问题讨论】:

    标签: linux bash shell ls


    【解决方案1】:

    您正在使用 PATH=$PATH 删除您的 $PATH: ls 不是内置命令,所以必须在 PATH 环境中

    【讨论】:

    • 我在哪里删除 $PATH?我必须在哪里使用 PATH=$PATH?
    • 一个更好的解释是PATH已经对shell有定义的含义(它指定在哪些目录中查找外部命令)和PATH(以及所有大写的变量名)不得用于您自己的目的。
    猜你喜欢
    • 2013-05-17
    • 1970-01-01
    • 2012-06-06
    • 2013-03-22
    • 2015-01-22
    • 2022-11-24
    • 1970-01-01
    • 2021-05-27
    • 2020-04-08
    相关资源
    最近更新 更多