Error: Tar command not found

Error: Tar command not found

    echo "Enter path of backup file e.g /tmp/backup/etc.tar.gz : "
    read PATH    #input was /tmp/backup/etc.tar.gz
    echo "Enter directory: " 
    read DIR    #input was /root/testing

    sudo tar -zvxf "$PATH" -C "$DIR"

当我运行脚本时,它说找不到命令。我尝试对变量使用任何类型的括号,但仍然无法正常工作。有帮助吗?

然而,当我 运行 命令 tar -zvxf /tmp/backup/etc.tar.gz -C /root/testing 时,它起作用了。

您正在将某些内容保存到 PATH 中,shell 将搜索这些内容以查找可执行文件。因此,当您使用该变量时,shell 找不到,比方说,tar,因为它不再在您的搜索路径中。使用不同的变量名。