X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Message-ID: Date: Wed, 22 Oct 2008 10:14:42 -0400 From: "Mark J. Reed" To: cygwin AT cygwin DOT com Subject: Re: bash: Word splitting but when? In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1224680840 DOT 20653 DOT ezmlm AT cygwin DOT com> 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 2008/10/22 sbremal > Hi All, > > Trying to get the right form of quoting and command substitution with output containing spaces. > > Given the following two lines in a bash script: > > x=$(echo '1 2 3 x') > y="$(echo '1 2 3 x')" Those are pretty much equivalent, but not because of when splitting is done. The only way the literal command x=1 2 3 x could be interpreted is as a request to run the command "2" with parameters "3" and "x", and with the environment variable "$x" set to "1". But this is ruled out syntactically before the command substituton ever takes place, so the result of the command substitution winds up being treated as if it were in grouping quotes even though it's not. Which is a feature, really, since it prevents unexpected command execution (e.g. x=$(echo foo rm -rf .) ). If you use something other than assignment, you can easily see the difference between the quoted and unquoted forms: $ set $(echo '1 2 3 x') $ echo $# 4 $ echo "$*" 1 2 3 x $ set "$(echo '1 2 3 x')" $ echo $# 1 $ echo "$*" 1 2 3 x -- 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/