Solved

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

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Squid Connection Pools 3 46
mobaxterm not able to change directory 28 108
linux installs 6 49
Install Predefined Certificate on Ubunto 4 17
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…
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 …
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…
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now