I have found that this command gives me the mime type from a file:
file --mime-type dog.jpeg
Output:
dog.jpeg: image/jpeg
I am now trying to create a bash checks if the mime is jpeg og png. However I am a bit stuck:
#!/bin/bash
$file_mime="file --mime-type dog.jpeg"
mime=`"${file_mime#*:}"`
if(mime=='image/jpg' OR mime=='image/png') do:
echo"Jpg or png"
done
Output:
./bash.sh: line 2: =file --mime-type dog.jpeg: command not found
./bash.sh: line 3: : command not found
Your first error is because you have a
$
prefix on your assignment. Your second error is because you are trying to combine the execution of the command with the processing of the results (stripping the filename from the result). As always with bash scripting there are lots of ways to achieve the same thing so this is just one, try:Then evaluate
$mime
but I suggest you search and read up on some bash scripting tutorials forif
statements etc as yourif
statement is not valid bash script.The declaration of variables in bash is without the dollar sign
$
:Now you want to perform a command substitution, the
file
variable being the result of the commandfile --mime-type dog.jpeg
. The way to do it is:Now you can echo the variable:
and to get the mime type: