#!/bin/sh # DarwinSysProfilerSection.sh # Thu Apr 2 00:44:25 PDT 2009 # Chieh Cheng # http://www.CynosureX.com/ # GNU General Public License (GPL) Version 2, June 1991 scriptName=`basename "$0"` showSystemProfileSection () { section=`echo "$1" | sed "s/:$//"` sectionSet=`Set_NewRandomName.sh` tempFile=`GetTempPathName.ksh "${scriptName}"` system_profiler > "${tempFile}" cat "${tempFile}" | grep "^[^ ].*:" | while read line do Set_Add.sh "${sectionSet}" "${line}" done result=`Set_Has.sh "${sectionSet}" "${section}:" | UnifyBoolean.sh` if [ ${result} -eq 1 ] then firstLine=`cat "${tempFile}" | grep -n "^${section}:" | Tokenize.sh ":" | Token.sh 1` pos=`Set_Show.sh "${sectionSet}" | grep -n "${section}:" | Tokenize.sh ":" | Token.sh 1` next=`expr ${pos} + 1` nextSection=`Set_Show.sh "${sectionSet}" | body ${next} ${next}` if [ "${nextSection}" = "${section}:" ] then lastLine=`cat "${tempFile}" | wc -l` else lastLine=`cat "${tempFile}" | grep -n "^${nextSection}" | Tokenize.sh ":" | Token.sh 1` lastLine=`expr ${lastLine} - 1` fi cat "${tempFile}" | body ${firstLine} ${lastLine} else echo "${section} is invalid. Valid sections are:" Set_Show.sh "${sectionSet}" fi rm "${tempFile}" Set_Delete.sh "${sectionSet}" } usage () { echo " Usage: ${scriptName} \"section\"" } if [ $# -eq 1 ] then location="$1" showSystemProfileSection "${location}" else usage echo echo " Available Sections:" system_profiler | grep "^[^ ].*:" | sed "s/:$//" | sed "s/^/ /" fi