#!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]"