Blame fixline1

Packit a69f91
#!expect --
Packit a69f91
# Synopsis: fixline1 newpath < input > output
Packit a69f91
# Author: Don Libes
Packit a69f91
Packit a69f91
# Description: change first line of script to reflect new binary
Packit a69f91
# try to match any of the following first lines
Packit a69f91
#!expect ...
Packit a69f91
#!../expect ...
Packit a69f91
#!expectk ...
Packit a69f91
#!foo/bar/expectk ...
Packit a69f91
#!/bin/sh ...  (beginning of multiline #! style)
Packit a69f91
#
Packit a69f91
set line1 [gets stdin]
Packit a69f91
if {"$line1" == "\#!/bin/sh"} {
Packit a69f91
    # if multi-line hack already in place, do nothing
Packit a69f91
    set header $line1
Packit a69f91
} else {
Packit a69f91
    # if single-line #!, switch to multi-line rewrite
Packit a69f91
Packit a69f91
    regexp "^#!(.*/)*(.*)" $line1 X X tail
Packit a69f91
    set header "#!/bin/sh\n"
Packit a69f91
    append header "# \\\n"
Packit a69f91
    append header "exec $tail "; append header {"$0" ${1+"$@"}}
Packit a69f91
}
Packit a69f91
puts -nonewline "$header\n[read stdin]"