From: Igal Koshevoy Date: 2008-06-28T06:55:50+09:00 Subject: Re: changing the shebang of ruby files best way ? Greg Donald wrote: > for file in *.rb; do > cp $file $file.tmp > sed -e "s/#!\/usr\/bin\/ruby\ -w$/#!\/usr\/bin\/env\ ruby\ -w/g" > $file.tmp >$file > rm $file.tmp > done > Or as sh and Ruby: for file in *.rb; do ruby -p -i.bak -e '$_.sub!(%r{(#!)(/usr/bin/ruby)( -w)?}, "\\1/usr/bin/env ruby -w")' "$file" done Or using find and Ruby to recurse the entire tree: find . -type f -name '*.rb' -exec ruby -p -i.bak -e '$_.sub!(%r{(#!)(/usr/bin/ruby)( -w)?}, "\\1/usr/bin/env ruby -w")' {} \; The "-i.bak" tells Ruby to do in-place replacements and backup originals to that file extension. -igal