How to check rar installation or not in Linux via Bash Script?

How to check installed rar unrar or not in Linux via Bash Script?

+4
source share
4 answers

Inspiration to receive from Michael Krelin - hacker post and python and / or expression, you can simply type this:

type -P rar > /dev/null && echo "rar is installed." || echo "rar is not installed." type -P unrar > /dev/null && echo "unrar is installed." || echo "unrar is not installed." 
0
source

If you can try

 type -P unrar >/dev/null && echo it\ installed\! 

This, of course, will only be detected in $PATH , and not anywhere in the system.

+2
source
 #!/bin/bash missing() { echo $1 is missing 1>&2 return 127 } RAR=`type -P rar || echo missing rar` UNRAR=`type -P unrar|| echo missing unrar` 

Use $ RAR or $ UNRAR in your script ... to do something. if they are absent, then the script will repeat that the command is absent

return 127 ensures that if you use the condition statement, it will fail if there are no files.

+2
source

Another solution:

 $whereis rar 
+1
source

Source: https://habr.com/ru/post/1385905/


All Articles