Solved

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

Posted on 2013-11-11
2
307 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 19

Accepted Solution

by:
simon3270 earned 500 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 19

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now