aboutsummaryrefslogtreecommitdiffstats
path: root/sysconfig
diff options
context:
space:
mode:
authorMatteo Croce <mcroce@redhat.com>2018-04-10 00:48:11 +0200
committerDee'Kej <deekej@linuxmail.org>2018-05-17 17:47:07 +0200
commitc29fbec03a13d7cfaac46af72aafc44f78902cc4 (patch)
treeb564471b3e638e0f6536e718b185e98855570a07 /sysconfig
parent402e41490782fc0549326be1a5d98bfa1f4ce35b (diff)
downloadinitscripts-c29fbec03a13d7cfaac46af72aafc44f78902cc4.tar
initscripts-c29fbec03a13d7cfaac46af72aafc44f78902cc4.tar.gz
initscripts-c29fbec03a13d7cfaac46af72aafc44f78902cc4.tar.bz2
initscripts-c29fbec03a13d7cfaac46af72aafc44f78902cc4.tar.xz
initscripts-c29fbec03a13d7cfaac46af72aafc44f78902cc4.zip
network-functions: use tr to upper case strings rather than awk
network-functions uses awk to tranform the mac address to upper case. Replace awk with tr which is two order of magnitude faster: $ time awk '{ print toupper($0) }' </usr/share/dict/words >/dev/null real 0m0,227s user 0m0,224s sys 0m0,004s $ time tr '[a-z]' '[A-Z]' </usr/share/dict/words >/dev/null real 0m0,005s user 0m0,000s sys 0m0,005s Also use here-strings instead of spawning a subshell and a pipe. Signed-off-by: Matteo Croce <mcroce@redhat.com>
Diffstat (limited to 'sysconfig')
-rw-r--r--sysconfig/network-scripts/network-functions6
1 files changed, 3 insertions, 3 deletions
diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions
index 343ae97c..4045af91 100644
--- a/sysconfig/network-scripts/network-functions
+++ b/sysconfig/network-scripts/network-functions
@@ -16,7 +16,7 @@ HOSTNAME="$(hostname)"
get_hwaddr ()
{
if [ -f /sys/class/net/${1}/address ]; then
- awk '{ print toupper($0) }' < /sys/class/net/${1}/address
+ tr '[a-z]' '[A-Z]' < /sys/class/net/${1}/address
elif [ -d "/sys/class/net/${1}" ]; then
LC_ALL= LANG= ip -o link show ${1} 2>/dev/null | \
awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,
@@ -160,10 +160,10 @@ source_config ()
;;
esac
if [ -n "$HWADDR" ]; then
- HWADDR=$(echo $HWADDR | awk '{ print toupper($0) }')
+ HWADDR=$(tr '[a-z]' '[A-Z]' <<<"$HWADDR")
fi
if [ -n "$MACADDR" ]; then
- MACADDR=$(echo $MACADDR | awk '{ print toupper($0) }')
+ MACADDR=$(tr '[a-z]' '[A-Z]' <<<"$MACADDR")
fi
[ -z "$DEVICE" -a -n "$HWADDR" ] && DEVICE=$(get_device_by_hwaddr $HWADDR)
[ -z "$DEVICETYPE" ] && DEVICETYPE=$(echo ${DEVICE} | sed "s/[0-9]*$//")