Gentoo Logo
Gentoo Spaceship

Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-osx
Lists: gentoo-osx: < Prev By Thread Next > < Prev By Date Next >
To: gentoo-osx@g.o
From: Grobian <grobian@g.o>
Subject: SheBang script
Date: Tue, 13 Sep 2005 22:58:05 +0200
Ok, I didn't really know where to put it, but I wanted to share my 
efforts with some people in an early phase.  This is the result of half 
an hour script-fu hacking.  I think it might be useful with regard to 
the upcoming portage.

See introductionary comment in the attach to get an idea what it does.

It currently only generates diff -u output, but it's quite easy to "| 
patch" it, and much safer for now to see what is happening, and if that 
is desired ;)

Fabian Groffen
Gentoo for Mac OS X
#!/usr/bin/env sh

# SheBang(tm) - a Gentoo script to rape files in a given directory for
# the purpose of supporting a variable 'prefix'.
# Fabian Groffen <grobian at gentoo (dot] org>
# 0.1 - initial mockup (20050913)
# This script searches for executable script files in the given
# directory and all its sub-directories and tries to process them in
# such a way, that the actual PATH environment controls how they are
# executed.  An example would be a script file having at the first line:
#    #!/usr/bin/perl
# this will be changed into:
#    #!/usr/bin/env perl
# where the actual location of 'perl' is resolved at runtime by 'env'
# using the current PATH environment.  The location of 'env' can be set
# using the variable ENV_PATH below.

# path to the env executable

if [ -z $1 ];
	echo "$0 needs an argument: the directory to process" > /dev/stderr
	exit 1;

# make a list with candidate files... well actually find 'em all and let
# file(1) tell us if it is text somehow.  Let awk do some magic to read
# the file and see if the first line starts with "#!".
CANDS=`find $1 -type f -exec file '{}' \; | grep text | cut -d: -f1 | \
awk '
	file = $1
	getline < file
	if ($0 ~ /^#!/) print file
# we basically have only candidate files in our hands now, so we should
# continue with the script-fu to see if we can do something with the
# "#!/some/where/file" thing...
for cand in $CANDS;
	# first get the first line of the file without the #!
	line=`head -n1 $cand | cut -c3-`
	# then see if we know this executable thing
	command=`echo $line | cut -d' ' -f 1`
	name=`basename $command`
	case "$name" in
			# we don't know these, and maybe we shouldn't touch them

	if [ $fine -eq 1 ];
		# we know these, and they are fine
		awk -v name="$name" \
				-v file="$cand" \
				-v envpath="$ENV_PATH" \
				-v command="$command" '
			BEGIN {
				for (i = 1; (getline line < file) > 0; i++) {
					if (i == 1) {
						out = "#!" envpath " " name
						out = out substr($0, length(command) + 2 + 1)
						print out
					} else {
						print line
		' | diff -u $cand -
Re: SheBang script
-- Kito
Lists: gentoo-osx: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
CHOST variable
Next by thread:
Re: SheBang script
Previous by date:
Re: CHOST variable
Next by date:
Re: SheBang script

Updated Jun 17, 2009

Summary: Archive of the gentoo-osx mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.