public inbox for gentoo-python@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-python@lists.gentoo.org
Cc: python@gentoo.org, "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-python] [PATCH 2/2] Replace 'head -n 1' calls with 'read' built-in.
Date: Tue, 23 Apr 2013 07:46:25 +0200	[thread overview]
Message-ID: <1366695985-3820-2-git-send-email-mgorny@gentoo.org> (raw)
In-Reply-To: <20130423074605.043d7456@pomiocik.lan>

The read built-in is simpler than forking and using pipes to relay
the first line of the file.
---
 gx86/eclass/distutils-r1.eclass    | 6 ++++--
 gx86/eclass/python-utils-r1.eclass | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
index 991d0a1..dd19440 100644
--- a/gx86/eclass/distutils-r1.eclass
+++ b/gx86/eclass/distutils-r1.eclass
@@ -394,9 +394,11 @@ _distutils-r1_rename_scripts() {
 	while IFS= read -r -d '' f; do
 		debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
 
-		if [[ "$(head -n 1 "${f}")" == '#!'*${EPYTHON}* ]]
+		local shebang
+		read -r shebang < "${f}"
+		if [[ ${shebang} == '#!'*${EPYTHON}* ]]
 		then
-			debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"
+			debug-print "${FUNCNAME}: matching shebang: ${shebang}"
 
 			local newf=${f}-${EPYTHON}
 			debug-print "${FUNCNAME}: renaming to ${newf#${D}/}"
diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
index 1ab8366..cd229f3 100644
--- a/gx86/eclass/python-utils-r1.eclass
+++ b/gx86/eclass/python-utils-r1.eclass
@@ -493,8 +493,8 @@ _python_rewrite_shebang() {
 
 	local f
 	for f; do
-		local shebang=$(head -n 1 "${f}")
-		local from
+		local from shebang
+		read -r shebang < "${f}"
 		shebang=${shebang%$'\r'}
 		debug-print "${FUNCNAME}: path = ${f}"
 		debug-print "${FUNCNAME}: shebang = ${shebang}"
-- 
1.8.1.5



  parent reply	other threads:[~2013-04-23  5:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-23  5:46 [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny
2013-04-23  5:46 ` [gentoo-python] [PATCH 1/2] Replace sed call with variable substitution Michał Górny
2013-04-23  5:46 ` Michał Górny [this message]
2013-04-30  5:37 ` [gentoo-python] [PATCHES] Use bash built-ins rather than external tools Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1366695985-3820-2-git-send-email-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-python@lists.gentoo.org \
    --cc=python@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox