Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

670 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