File: fixline1

package info (click to toggle)
expect 5.45.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,016 kB
  • sloc: ansic: 17,965; sh: 7,445; tcl: 384; makefile: 191; exp: 10
file content (25 lines) | stat: -rwxr-xr-x 708 bytes parent folder | download | duplicates (11)
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]"