I'm working on a script to retrieve the serial number from a host running OS X, and then append the number to the end of a URL.
#!/bin/bash
# Retrieve serial number in OS X, then append serial number to URL
### Retrieve serial number ###
function serial_number(){
local serialnum=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
# Use system_profiler to poll info, then print 4th column of Serial from SPHardwareDataType
# write_header "Serial Number"
echo "${serialnum}"
echo ""
}
### Append serial number to URL ###
function apple_link(){
local appleurl=$"https://support.apple.com/specs/${serialnum}"
echo "${appleurl}"
echo ""
}
### Testing ###
apple_link
I get this as a result: https://support.apple.com/specs/
, which does not show the appended serial number. I'm not entirely sure why this is?
Any comments or suggestions on how to "fix" my oversight would be greatly appreciated. Thanks in advance.
serial_number
which is never called, a local variableserialnum
and a reference toserial_num
; seems weird – ridgy Feb 08 '17 at 15:54