From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailsrv.cs.umass.edu (mailsrv.cs.umass.edu [128.119.240.136]) by sourceware.org (Postfix) with ESMTPS id 6AFC7386F82C for ; Fri, 8 Jan 2021 13:21:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6AFC7386F82C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cs.umass.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=moss@cs.umass.edu Received: from [192.168.0.14] (c-24-62-203-86.hsd1.ma.comcast.net [24.62.203.86]) by mailsrv.cs.umass.edu (Postfix) with ESMTPSA id 3A58A400F0B5; Fri, 8 Jan 2021 08:21:06 -0500 (EST) Reply-To: moss@cs.umass.edu Subject: Re: Limitation of setenv for tcsh: Too many arguments To: "KAVALAGIOS Panagiotis (EEAS-EXT)" , "cygwin@cygwin.com" References: <0d66260ff1314bf693caa6cbb6647547@BELBRU-EXMP101.eeas.europa.eu> From: Eliot Moss Message-ID: <4a7542e2-9f38-9e72-3229-ca39feab66d1@cs.umass.edu> Date: Fri, 8 Jan 2021 08:21:06 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <0d66260ff1314bf693caa6cbb6647547@BELBRU-EXMP101.eeas.europa.eu> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jan 2021 13:21:07 -0000 On 1/8/2021 5:13 AM, KAVALAGIOS Panagiotis (EEAS-EXT) wrote: > Dear all, > > There is a limitation for tcsh (setenv: Too many arguments) to set the PATH environmental variable as you can see in the attached file with the steps to reproduce it. It probably looks like tcsh limitation and not Cygwin. The "set path=( ${HOME}/bin $path)" is not complaining and sets the path, but it also interprets the space in the paths as a separator. The only Cygwin related issue is probably the /usr/bin that it is added twice. Any workarounds? I saw another response, but will add that I typically do something more like: set PATH="${HOME}/bin:${PATH}" THat takes care of quoting. However, you want to avoid duplicate entries. Something like this helps with that: [ -z "${PATH##*${HOME}/bin:*}" ] || { PATH="${HOME}/bin:${PATH}" } I suppose it is slightly dangerous in that it would also match /foo/${HOME}/bin, but ${HOME} is absolute and such a match seems unlikely. Still, you could do: [ -z "${PATH##${HOME}/bin:*}" ] to check if it is first on the path, and [ -z "${PATH##*:${HOME}/bin:*}" ] to see if it is in the middle, and [ -z "${PATH##*:${HOME}/bin}" ] to see if it as at the end. This leads to: [ -z "${PATH##${HOME}/bin:*}" ] || [ -z "${PATH##*:${HOME}/bin:*}" ] || [ -z "${PATH##*:${HOME}/bin}" ] || { PATH="${HOME}/bin:$PATH}" } Because of the three first/middle/end possibilities, this is what comes to mind. _Maybe_ you could get a more elegant solution using bash arrays, but this is not that long as a piece of bash code. Regards - Eliot Moss