MacOS – extract if_index without grep from scutil –dns

command linemacosterminal

I'm using the grep command to extract active interfaces from the output of the scutil command with the --dns option.

$ scutil --dns | grep 'if_index'

I am suspecting if a user's machine with different system language (Spanish, Chinese, etc) the text 'if_index' will change and the above mentioned command will not produce the right result. Is my suspicion right? If so could someone tell what is the right way to perform the above operation?

Best Answer

If you look at the executable itself, /usr/sbin/scutil with the strings command you can see that those strings are hardcoded directly into the executable.

$ strings /usr/sbin/scutil | grep 'if_index'
  if_index : %d (%s)

Additionally this CLI's output remains the same when you try changing the LANG=.. or LC_ALL=.. environment variables. For example:

$ LANG="zh_CN.UTF-8" scutil --dns | grep 'if_index'
  if_index : 10 (en0)

$ LC_ALL="zh_CN.UTF-8" scutil --dns | grep 'if_index'
  if_index : 10 (en0)

Doing this with another CLI tool such as git translates the output:

$ LC_ALL="zh_CN.UTF-8" git --help
用法:git [--version] [--help] [-C <路径>] [-c <名称>=<取值>]
           [--exec-path[=<路径>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<路径>] [--work-tree=<路径>] [--namespace=<名称>]
           <命令> [<参数>]

这些是各种场合常见的 Git 命令:

开始一个工作区(参见:git help tutorial)
   clone      克隆一个仓库到一个新目录
   init       创建一个空的 Git 仓库或重新初始化一个已存在的仓库

All this leads me to believe that the output will not change.