Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Tar command not found

Tags:

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"

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.

like image 775
Patrick Kang Avatar asked Dec 02 '25 00:12

Patrick Kang


1 Answers

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

like image 185
Eric Renouf Avatar answered Dec 03 '25 19:12

Eric Renouf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!