Determining the version of Firefox on OS X

If you wish to determine the version of Firefox installed on an OS X from a command line interface (CLI), you can open a Terminal window and use the command shown below:

$ /Applications/ -v
Mozilla Firefox 45.8.0

You can also find the information in the Info.plist file found at /Applications/ The version number will be on the line following the "key" line for CFBundleGetInfoString and also after the "key" line for CFBundleShortVersionString .

Tutor for Mac OS X El Capitan
Tutor for Mac OS X El Capitan
1x1 px

        <string>Firefox 45.8.0</string>


So I could find the version using the grep command.

$ grep -A 1 CFBundleShortVersionString /Applications/ | grep string

If I just want to see the version number without the surrounding "string" tags, I can combine grep and sed commands as shown below:

$ grep -A 1 CFBundleShortVersionString /Applications/ | grep string | sed -E -e 's/<\/?string>//g'

The command that I want sed to execute is contained within single quotes. The s at the beginning of the command indicates I want to perform a "substitute" operation. Within the first pair of forward slashes (/), I place the string I want sed to replace. Sed can use regular expressions. In a regular expression, the question mark character indicates that the preceding element can be matched zero or more times. Since I want to eliminate both <string> and </string> I can put a question mark after a forward slash, i.e., /?, to indicate I want to look for both "string" and "/string". But, because I am using the forward slash to separate the pattern for which I want sed to search and the replacement pattern, i.e., s/pattern/new_pattern, I need to indicate to sed that I want it to treat the forward slash before "string" as just a regular character, so I need to "escape" the meaning it would normally assign to it with an "escape character," which is the backslash (\) character. Since I want sed to eliminate the pattern it finds rather than replace it with some other pattern, I can use s/pattern// to indicate that it should eliminate the old pattern. By putting a g at the end of the command, I indicate that I want sed to replace the pattern "globally" on the line, i.e., not just for the first instance it finds, to ensure it removes both <string> and </string>.

If I want to remove the whitespace before the version number, I need to remove the tab that precedes the version number. You can see that it is one tab character rather than multiple space characters by piping the output into the od utility as shown below:

$ grep -A 1 CFBundleShortVersionString /Applications/ | grep string | sed -E -e 's/<\/?string>//g' | od -c
0000000   \t   4   5   .   8   .   0  \n                                

The \t represents the tab character and the \n at the end of the line indicates a newline character. But sed doesn't recognize \t as representing the tab character. However, I can tell it to look for the tab character from the Terminal window's Bash shell interface by using ^V, i.e., by hitting the control and v keys simultaneously followed by hitting the tab key. You won't see any representation of the tab character on the line, other than additional space appearing, but sed then knows to look for the tab character. After hitting the tab key, I can put an asterisk (*) which indicates in a regular expression that the preceding element, e.g. a tab character in this case, should be matched zero or more times.

$ grep -A 1 CFBundleShortVersionString /Applications/ | grep string | sed -E -e 's/        *<\/?string>//g'

Related articles:

  1. Determining the version of the OS and applications under OS X