I would like to be able to extract (from within a shell script) the attributes of an IPS package. Basically I'm after exact same information as is listed with the pkg info command, but unfortunately this command list information in a format which is not very friendly to read from within a script. Example below:

$ pkg info archiver/gnu-tar
          Name: archiver/gnu-tar
       Summary: GNU version of the tar archiving utility
   Description: Tar is a program for packaging a set of files as a single
                archive in tar format.
      Category: Development/GNU
         State: Installed
     Publisher: solaris
       Version: 1.26
 Build Release: 5.11
Packaging Date: October 19, 2011 09:11:16 AM
          Size: 1.73 MB
          FMRI: pkg://solaris/archiver/gnu-tar@1.26,5.11-

I was hoping for something like pkg get-property pkg.summary archiver/gnu-tar to be available as a command but can't find such command. I would really hate to try to parse the above output. Secondly the man pages clearly states that the output from pkg info is intended to be read by humans, not machines.

2 Answers 2


Most of what pkg info reports comes from the set actions in the package which define package attributes and other metadata. For your example of archiver/gnu-tar:

% pkg contents -t set -o name,value archiver/gnu-tar
NAME                          VALUE
info.classification           org.opensolaris.category.2008:Development/GNU
info.source-url               http://ftp.gnu.org/gnu/tar/tar-1.26.tar.bz2
info.upstream-url             http://www.gnu.org/software/tar/
org.opensolaris.arc-caseid    PSARC/2000/488
org.opensolaris.consolidation userland
pkg.description               Tar is a program for packaging a set of files as a single archive in tar format.
pkg.fmri                      pkg://solaris/archiver/gnu-tar@1.26,5.11-
pkg.summary                   GNU version of the tar archiving utility
variant.arch                  ['i386', 'sparc']

% pkg contents -H -t set -o value -a name=pkg.summary archiver/gnu-tar
GNU version of the tar archiving utility
  • Perfect! You variation of pkg contents was indeed what I was looking for. Not very logical that you would use the 'set' action when all you want is to display a value. I would NEVER have figured this out by reading the pkg man page.
    – peterh
    Aug 20, 2012 at 18:47

Here is how I would do it by parsing pkg info output:

$ pkg info archiver/gnu-tar | nawk '
/^ *[A-Za-z ]*:/ {
    gsub("^ *","",$1)
    if(NR>1) printf("\n")
    gsub(" ","_",name);
  gsub("^ *","",$1)
} ' | sed -e 's/= /="/' -e 's/$/"/'


Summary="GNU version of the tar archiving utility"
Description="Tar is a program for packaging a set of files as a singlearchive in tar format."
Packaging_Date="October 19, 2011 09:11:16 AM"
Size="1.73 MB"
  • Thank you so much. That is truly an amazing piece of AWK code. I wonder what would happen if the Description field would contain a colon? I'll leave the question open for some days to see if somebody can come up with a native command on how to do this. If nothing comes along I'll accept your answer. Thanks again buddy.
    – peterh
    Aug 16, 2012 at 10:43
  • Nothing will happen if the description field contains a colon as only the first one is processed. By the way, I just enhanced my script to replace spaces by underscores in the field names for the script to output valid shell script assignments.
    – jlliagre
    Aug 16, 2012 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.