From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 0E946385840A for ; Fri, 10 Mar 2023 18:42:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E946385840A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102e.google.com with SMTP id kb15so6208781pjb.1 for ; Fri, 10 Mar 2023 10:42:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678473757; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5G5l70pTNUkugzU0HDCuQCyjVkV7rhYgcEFljSOuaG0=; b=BSRzgTT5S5yO/Kr+cHbxVcMekKnqGcVZm5xWGhAEDYtXSkTKYaOcVUMPb2gFWOhlQe MCNURMDnRS2CRDbQzmmhYlLGyaFvBJDzUBvTnXnG/G/AQLHvbDVyps0T1VGQNchXdRTf dtfey9RGFSHt75T7biP6ccUSwmLoWuCPV/2sKkFeGCjWcvB1ufGTRcuzClR7oD5CbKDu n9gSWi8vp0e260yS73xUAJw2CsMCBjSeZa8AHEhD9RgT0fD9uPPSK4GIKcqdMsW0YWxd pu6hvZr5xsIAjZkZ/4Ppw4KI8TvHMXRhP1QETl+z2+CZ6KdUhyWh0zt7s7Y/Ai6/GGDW j+MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678473757; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5G5l70pTNUkugzU0HDCuQCyjVkV7rhYgcEFljSOuaG0=; b=OcybL54o389TaH+cszSxLwAM+F3Vdsd83g0N/tUqZ6ppZTMe0jpPZc9E0TUe7xH4iW 8Hf7GDFyS1hnCqPSVDUz2lfexndf/4580AA0bt6QVcEekBzRs5wCRory2BCV8kOAqOBV /70ujUf6CwAMTReRGeiFZ0Do1dLNKnHE7N8ZeaZxGQp2g9jPt1Om4aQ/3hveIx27G39X +Y1GpPsFK4PL0ph1svzoG9YPUQ7hWG3lQyFnhCl7dwpVPxreG5vNxQOxEogRkaz0J7tX AW7oahmhAoOWNzzN39hy9DN5t5nZgzu7uZN4qd5hfAS/k9QdVYaN4i8LJ2pPEKO6+/jU pv5g== X-Gm-Message-State: AO0yUKVu8MqoZNBXiBKxF9MAFGrTnp/wtCJxtML0wXqsKf9VMdyXiYvc r3hVwyFpEEGJqdiHJT9ZpYqM2vJh3Aa3wUo2g5tKutkUZbLKVTJvQ/A= X-Google-Smtp-Source: AK7set+kI7qK5b+utQzfLCcQnD4LY9r0FwhxT/DjrxxO4jY57Z6ZU7oORzDNyVbIC7PE70Ii9h08O4DWO9khGPoVI8I= X-Received: by 2002:a17:903:26d6:b0:19b:fe3:c948 with SMTP id jg22-20020a17090326d600b0019b0fe3c948mr9863821plb.12.1678473757089; Fri, 10 Mar 2023 10:42:37 -0800 (PST) MIME-Version: 1.0 References: <63cccff3-9487-3588-5dd8-e49499882280@cornell.edu> In-Reply-To: From: Backwoods BC Date: Fri, 10 Mar 2023 10:42:25 -0800 Message-ID: Subject: Re: General scripting issues vs. Linux To: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Mar 10, 2023 at 8:16=E2=80=AFAM Brian Inglis via Cygwin wrote: > > On 2023-03-10 06:59, Ken Brown via Cygwin wrote: > > On 3/10/2023 8:47 AM, Markus Becker via Cygwin wrote: > >> I am quite an newby in Cygwin scripting and encountered several execut= ion > >> issues with bash scripts. For example, when i try to execute the follo= wing > >> simple scriptfile "skript1.sh": > >> # This is a testscript > >> Statement=3D"This is the testscript number 3" > >> FILE=3D"home/mbecker/Secure_Copy_Beispiel.txt" > >> ls -l $FILE > >> echo $Statement > >> echo The file is $FILE > >> i got these results: > >> $ ./skript1.sh > >> ls: cannot access 'home/mbecker/Secure_Copy_Beispiel.txt'$'\r\r': No s= uch > ^^^^^ > >> file or directory > >> This is the testscript number 3 > >> The file is home/mbecker/Secure_Copy_Beispiel.txt > >> or another results from a different script: > >> $ ./skript7.sh > >> ./skript7.sh: line 3: $'clear\r': command not found > ^^^ > >> Dr=E2=96=92cken sie beliebige Tasten und dann return > >> ': not a valid identifierd: `TASTE > >> These are just two of several issues coming up with bash scripting in > >> Cygwin. Maybe this is merely a corse problem with my platform > >> understanding. But why is Cygwin calling errors when performing standa= rd > >> Linux bash commands? Is it due to a different syntax? Or is it even si= mpler? > > > It looks like your scripts have CRLF line endings. > > Utilities such as coreutils, gawk, grep, sed, etc. Cygwin packages had Cy= gwin > tweaks removed in 2017 to be compatible with Linux and other platforms in > handling '\r' before newlines, except for the single exception of Cygwin = text > mounts, where '\r' may be stripped if a program opens a file from that mo= unt in > text "t" mode, and may be added on writes to a file in text "t" mode on a= text > mount: > > https://www.cygwin.com/cygwin-ug-net/using-textbinary.html > > discussions: > > https://cygwin.com/legacy-ml/cygwin/2017-02/msg00152.html > https://cygwin.com/legacy-ml/cygwin/2017-02/msg00188.html > https://cygwin.com/legacy-ml/cygwin/2017-02/msg00189.html > > Install package dos2unix which conveniently strips the offending junk fro= m your > scripts and files e.g. > > d2u -k skript*.sh > > Install and use Cygwin editors and utilities, or check editor and utility > settings to ensure they are not set to behave like Windows e.g. gvim set > fileformat=3Dunix termencoding=3Dutf-8 fileencoding=3Dutf-8 in your ~/.gv= imrc ~/.vimrc > ~/.virc ~/.exrc; emacs (set-buffer-file-coding-system 'mule-utf-8-unix) i= n > ~/.emacs, type C-x C-q C-m f mule-utf-8-unix, or do the equivalent in mor= e > sophisticated initializations (auto)detecting file type, encoding, and fo= rmat; > for git config --global core.autocrlf =3D input, see: > > https://stackoverflow.com/questions/3206843/how-line-ending-conversions-w= ork-with-git-core-autocrlf-between-different-operat > > -- > Take care. Thanks, Brian Inglis Calgary, Alberta, Canada As a matter of expediency, I always pass files through '| tr -d '\r' |' when reading them. This is harmless on Linux and you don't have to worry whether or not your target system has 'd2u' installed since I believe that 'tr' is part of all base installations. It also means you don't have to worry about whether or not a particular program handles '\r' automagically. I find that it is also a good idea to save all script files as UTF-8 so that they can handle Windows filenames with emojis and such in them when explicitly named in the script.