X-Spam-Check-By: sourceware.org Date: Wed, 14 Feb 2007 21:45:10 +0200 Message-Id: <200702141945.l1EJjA2S024281@beta.mvs.co.il> From: "Ehud Karni" To: eric_backus AT alum DOT mit DOT edu Cc: cygwin AT cygwin DOT com Subject: Re: Unable to run even simple batch scripts any more In-reply-to: (message from Eric Backus on Tue, 13 Feb 2007 00:56:24 +0000 (UTC)) Reply-to: ehud AT unix DOT mvs DOT co DOT il References: <021b01c74ef4$b38a71d0$8532a8c0 AT M6> X-Mailer: Emacs 21.3.1 rmail (send-msg 1.108) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-8-i Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Tue, 13 Feb 2007 00:56:24 Eric Backus wrote: > > Obviously, the horse is still alive and attempting to limp along. I predict > it'll stay alive for quite some time longer. > [snip] > > * Workaround inserting "set -o igncr" is impractical when there are lots of > scripts. [snip] Among my many scripts, there are some with DOS (i.e. CR LF) ending that I prefer to leave as is (mostly to be able to edit them with notpad). I wrote a little script that can fix bash scripts with CRs by adding the required "set -o igncr" line. Notes: 1. You can, of course, replace the `awk' with a simple `d2u' if you don't need the CRs at all. 2. Change the `grep' arguments (mostly the "-r" and the files list) to suit your needs. 3. This script will fail on a file with ":" in its name (which can occur only on manged mounts, because of the OS limitations) Ehud. -------------------- cut here -------------------- #! /bin/bash -ex chk_it () { while read HEAD do echo " Checking $HEAD" # show some progress case "$HEAD" in *":1:#"*"^M" ) # ONLY (ba)sh files with CR ending SNM=`echo "$HEAD" | cut "-d:" -f1` # extract script name echo "Fixing $SNM ++++++++++++++++++++" cp -p "$SNM" "$SNM"-new # copy with permissions awk ' BEGIN { IA = 0 } $0 ~ /^[ ]*#/ { print $0 ; next } { if ( IA == 0 ) { print "set -o igncr #\r" ; IA = 1 ; } print $0 ; } ' < "$SNM" > "$SNM"-new # add "set -o igncr" after initial comments mv "$SNM" "$SNM"-old # save old script mv "$SNM"-new "$SNM" # rename new to current esac done } # ---------------------------------------------------------------------- grep -E -H -I -m 1 -n -U -r -e '^#![ ]*/bin/(ba)?sh' * \ | cat -v | chk_it # check & replace CR scripts ##################### end of fix-cr.sh script #################### -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ GnuPG: 98EA398D Better Safe Than Sorry -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/