quotes in bash script

2013-07-12 Thread gscantlen
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 



when I execute the script: 
bash -x script.sh 


I get: 
+ PARAMS_FOR_LS='-alst "dir with spaces"' 
+ echo -alst '"dir' with 'spaces"' 
-alst "dir with spaces" 
+ ls -alst '"dir' with 'spaces"' 
ls: cannot access "dir: No such file or directory 
ls: cannot access with: No such file or directory 
ls: cannot access spaces": No such file or directory 

why the extra quotes ?? 




script with ssh and filenames with spaces

2013-07-17 Thread gscantlen
plz help with this script, 

I wish to ssh this command to several hosts: 
ls -alst "dir_with_spaces" 

This script is close but I need DOUBLE-quotes around the remote command s 
#! /bin/bash 

PARAMS_FOR_LS=(-alst "dir with spaces") 

# get directory of local system 
ls "${PARAMS_FOR_LS[@]}" 

# get directory of remote systems 

#do search 'x' for a hostname; get host1 
ssh host1 ls "${PARAMS_FOR_LS[@]}" 

#do search 'y' for a hostname; get host2 
ssh host2 ls "${PARAMS_FOR_LS[@]}" 

#do search 'z' for a hostname; get host3 
ssh host3 ls "${PARAMS_FOR_LS[@]}" 


I have tried several variations of eval and echo. 
plz help