public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
* [PATCH cygport] Improve __fix_shebang()
@ 2021-01-25 15:17 Lemures Lemniscati
  0 siblings, 0 replies; only message in thread
From: Lemures Lemniscati @ 2021-01-25 15:17 UTC (permalink / raw)
  To: cygwin-apps

[-- Attachment #1: Type: text/plain, Size: 753 bytes --]

Hi!

This is a patch for improving __fix_shebang(),
in case a shebang uses 'env'.
(just gobbling a word after 'env')


diff --git a/lib/src_install.cygpart b/lib/src_install.cygpart
index cca7347..d101f5b 100644
--- a/lib/src_install.cygpart
+++ b/lib/src_install.cygpart
@@ -103,7 +103,9 @@ __fix_shebang() {
 			continue
 		fi
 
-		sed -i -e "s|#! */[^ ]*\(.*\)|#! ${interp}\1|" ${x}
+		# Note: This pattern does not work when 'env' with
+		#       any option or any variable-setting.
+		sed -i -e 's;^#![[:space:]]*\(\([^[:space:]]*/\|\)env[[:space:]]*[^[:space:]][^[:space:]]*\|[^[:space:]]*\)\(.*\);#!'"${interp}"'\3;' ${x}
 	done
 }
 
-- 
2.30.0

A test script for the same pattern is attached as a.sh

Regards,
Lem


[-- Attachment #2: a.sh --]
[-- Type: application/octet-stream, Size: 544 bytes --]

#!/bin/bash

interp=xxxINTERPxxx

sed -e '=;P' \
    -e 's;^#![[:space:]]*\(\([^[:space:]]*/\|\)env[[:space:]]*[^[:space:]][^[:space:]]*\|[^[:space:]]*\)\(.*\);#!'"${interp}"'\3;' \
<<_END
#!/bin/bash foo  bar  baz
#!/bin/bash  foo  bar  baz
#! /bin/bash  foo  bar  baz
#!  /bin/bash  foo  bar  baz
#!/usr/bin/env foo  bar  baz
#!/usr/bin/env  foo  bar  baz
#! /usr/bin/env  foo  bar  baz
#!  /usr/bin/env	foo  bar  baz
#!	 /bin/env   foo  bar  baz
#!	 /bin/env	foo  bar  baz
#!	 /bin/env 	 foo  bar  baz
#!/this/will/fail/env TZ=EST bash
_END

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-25 15:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25 15:17 [PATCH cygport] Improve __fix_shebang() Lemures Lemniscati

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).