Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linux Shell Scripting: Automatically get mime if mime value not application/x-not-regular-file

Posted on 2013-11-11
2
Medium Priority
?
351 Views
Last Modified: 2013-11-11
This gets the mime-type of all files in a directory:
for f in *
do
x=`file -ib $f`
echo $x
done

Open in new window

If it cannot determine the mime-type then the value of $x becomes: "application/x-not-regular-file" however in that case I would like the value of $x to be: "application/force-download"
0
Comment
Question by:hankknight
  • 2
2 Comments
 
LVL 20

Accepted Solution

by:
simon3270 earned 2000 total points
ID: 39639819
If the text in its entirety is "application/x-not-regular-file" then you could have:
if [ "$x" = "application/x-not-regular-file" ]; then
  x="application/force-download"
fi

Open in new window

0
 
LVL 20

Expert Comment

by:simon3270
ID: 39639842
If you want to match up to the semicolon, you could do something like:
if [ "${x#application/x-not-regular-file;" != "$x" ]; then
  x="application/force-download"
fi

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Utilizing an array to gracefully append to a list of EmailAddresses
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question