bash

Display image properties with bash

The following bash script shows how to capture image properties from ImageMagick:

#!/bin/bash
a=`identify xa.jpg`
strarray=($a)
echo 'format: ' ${strarray[1]}
echo 'dimensions: ' ${strarray[2]}
echo 'filesize: ' ${strarray[6]}

xa.jpg is an image which is stored in the same directory as this script.

identify is an ImageMagick utility. The output of identify xa.jpg is:

Escaping single quotes inside single quotes in bash

In bash, you can use the backslash character ("\") to escape any character. However, if a single quote is inside single quotes, it cannot be escaped with a backslash character. For example:

alias ycd='some_command'

works fine but

alias ycd='command -option 'something''
alias ycd='command -option \'something\''

both of the above return errors.

A trick around this problem is to use both quotes i.e. use double quotes to surround the single quote and single quotes again to surround the single quote.