Gentoo Archives: gentoo-python

From: "Michał Górny" <mgorny@g.o>
To: gentoo-python@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-python] [PATCH 2/2] Replace 'head -n 1' calls with 'read' built-in.
Date: Tue, 23 Apr 2013 05:45:11
Message-Id: 1366695985-3820-2-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-python] [PATCHES] Use bash built-ins rather than external tools by "Michał Górny"
1 The read built-in is simpler than forking and using pipes to relay
2 the first line of the file.
3 ---
4 gx86/eclass/distutils-r1.eclass | 6 ++++--
5 gx86/eclass/python-utils-r1.eclass | 4 ++--
6 2 files changed, 6 insertions(+), 4 deletions(-)
7
8 diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
9 index 991d0a1..dd19440 100644
10 --- a/gx86/eclass/distutils-r1.eclass
11 +++ b/gx86/eclass/distutils-r1.eclass
12 @@ -394,9 +394,11 @@ _distutils-r1_rename_scripts() {
13 while IFS= read -r -d '' f; do
14 debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
15
16 - if [[ "$(head -n 1 "${f}")" == '#!'*${EPYTHON}* ]]
17 + local shebang
18 + read -r shebang < "${f}"
19 + if [[ ${shebang} == '#!'*${EPYTHON}* ]]
20 then
21 - debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"
22 + debug-print "${FUNCNAME}: matching shebang: ${shebang}"
23
24 local newf=${f}-${EPYTHON}
25 debug-print "${FUNCNAME}: renaming to ${newf#${D}/}"
26 diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
27 index 1ab8366..cd229f3 100644
28 --- a/gx86/eclass/python-utils-r1.eclass
29 +++ b/gx86/eclass/python-utils-r1.eclass
30 @@ -493,8 +493,8 @@ _python_rewrite_shebang() {
31
32 local f
33 for f; do
34 - local shebang=$(head -n 1 "${f}")
35 - local from
36 + local from shebang
37 + read -r shebang < "${f}"
38 shebang=${shebang%$'\r'}
39 debug-print "${FUNCNAME}: path = ${f}"
40 debug-print "${FUNCNAME}: shebang = ${shebang}"
41 --
42 1.8.1.5