summaryrefslogtreecommitdiff
path: root/fixline1
blob: 113e9bbc70dde7560f235e61dbf903d4d06980c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!expect --
# Synopsis: fixline1 newpath < input > output
# Author: Don Libes

# Description: change first line of script to reflect new binary
# try to match any of the following first lines
#!expect ...
#!../expect ...
#!expectk ...
#!foo/bar/expectk ...
#!/bin/sh ...  (beginning of multiline #! style)
#
set line1 [gets stdin]
if {"$line1" == "\#!/bin/sh"} {
    # if multi-line hack already in place, do nothing
    set header $line1
} else {
    # if single-line #!, switch to multi-line rewrite

    regexp "^#!(.*/)*(.*)" $line1 X X tail
    set header "#!/bin/sh\n"
    append header "# \\\n"
    append header "exec $tail "; append header {"$0" ${1+"$@"}}
}
puts -nonewline "$header\n[read stdin]"