On Fri, 12 Jul 2013, gscant...@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