Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Open multiple terminal windows using a script and running a script in the new xterm 7 49
sqlldr issue 1 35
Migrating a Linux server to VMware 3 141
Renaming with batch file 9 108
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

751 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