bash - 错误 : Tar command not found

标签 bash shell unix tar

    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因为它不再在您的搜索路径中。使用不同的变量名称。

关于bash - 错误 : Tar command not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31627322/

相关文章:

linux - 如何在新的终端窗口或选项卡中使用从终端 shell 脚本设置的变量? (OSX)

linux - 无法通过 putty 和 winscp 连接服务器

linux - 在 shell 中打印非 ascii/unicode 字符

linux - Bash 脚本不稳定的结果

git - 在多个存储库上运行 git gc

Bash shell 脚本从文件名中查找丢失的文件

python - 是否可以在 CLI 中修改 json 对象?

linux - Jenkins:在 bash 脚本中插入特殊字符

无法使用在 Solaris 上运行的代码在 Linux 上从 `siginfo_t` 检索 PID

通过 fork() 在 C 中创建多个进程和模拟