bash 错误:找不到 Tar 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31627322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:22:00  来源:igfitidea点击:

Error: Tar command not found

bashshellunixtar

提问by Patrick Kang

    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"

when I ran the script, it said that the command was not found. I tried using whatever kind of brackets for the variables but still not working. Any help?

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

However when I ran the command tar -zvxf /tmp/backup/etc.tar.gz -C /root/testing , it worked.

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

回答by Eric Renouf

You're saving something into PATHwhich is what the shell will search to find the executables. So when you use that variable the shell can't find, say, tarbecause it is no longer in your search path. Use a different variable name.

您正在保存一些东西PATH,shell 将在其中搜索以查找可执行文件。因此,当您使用该变量时,shell 无法找到,例如,tar因为它不再在您的搜索路径中。使用不同的变量名称。