Display image properties with bash

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

a=`identify xa.jpg`
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:

Bash Shell Scripting

A shell script is a code (script) written for the shell or command line interpreter of an operating system such as Unix. It allows users to automate tasks which would be cumbersome to execute manually. For example renaming 2000 files. You could do it by 2000 mv commands or write up a 3 line shell script to do it for you.

A shell script can be written in any shell scripting language installed on the system. The most widely used shell is the Bash Shell. Others include csh, ksh, tcsh, etc. Here we would only be discussing bash shell.

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.