Michael GilletteBerg
Michael GilletteBerg

Reputation: 31

Mac Script Question: adding colon as a String

I'm trying to add a colon after the display model. Basically I would like the output to be:

model: serialnumber

I'm having trouble adding : as a string.

My script is written in a way where it only gives an output if an external monitor exists.

#!/bin/sh

#sets serial = serialnumber

serial=`system_profiler SPDisplaysDataType | grep -i "Display Serial Number" | sed -e 's/^[ \t]*//' | cut -d " " -f 4`

#sets displayModel = model serialnumber

displayModel=`system_profiler SPDisplaysDataType | awk '/Resolution:/{print x}; {x=$0};/Framebuffer Depth:/{getline;print$3}' | sed -e 's/^ *//g;s/://g'`

#if serial exists, echo model serialnumber

if [ ! -z "$serial" ]

then

#Outputs: model serialnumber

echo "<result>$displayModel</result>"

fi

Upvotes: 2

Views: 69

Answers (1)

Michael GilletteBerg
Michael GilletteBerg

Reputation: 31

-Use printf to keep each model and serialnumber output on the same line.

-Using : was not working but using | instead will work.

-I also added a , at the end.

displayModel = system_profiler SPDisplaysDataType | awk '/Resolution:/{printf x; printf" | "}; {x=$0};/Framebuffer Depth:/{getline;printf$4; print", "}' | sed -e 's/^ *//g;s/://g'

-Output is:

model | serialnumber,

model | serialnumber,

Upvotes: 1

Related Questions