bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: quotes in bash script


From: Chris F.A. Johnson
Subject: Re: quotes in bash script
Date: Sat, 13 Jul 2013 01:27:05 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Fri, 12 Jul 2013, gscantlen@comcast.net wrote:

I want a script to execute the command:
ls -alst "dir with spaces"


The script looks like this :
#! /bin/bash

PARAMS_FOR_LS="-alst \"dir with spaces\""

echo $PARAMS_FOR_LS

ls $PARAMS_FOR_LS

   $PARAMS_FOR_LS is subject to word splitting.

   Try this instead:

PARAMS_FOR_LS=( -alst "dir with spaces" )
ls "${PARAMS_FOR_LS[@]}"

   See also <http://mywiki.wooledge.org/BashFAQ/050>.

--
   Chris F.A. Johnson, <http://cfajohnson.com/>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]