The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to build a command into a string rather than execute the command littlejon Shell Programming and Scripting 1 05-29-2008 05:05 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
sed command not running mmunir Shell Programming and Scripting 3 04-17-2008 11:02 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl Linux 5 07-30-2007 05:26 AM
running command more than twice in one second? Terrible Shell Programming and Scripting 4 12-10-2006 08:45 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-03-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
Stumble this Post!
Running a String as a command, zsh.

I have a shell script that is building a string that consists of the parts of a command that I want run at the end of the string. So it looks like this:

$PART1=/path/to/command
$PART2="-arg1"
$PART3="-arg2"
and so on.

At the end of the command is a list of files I get from a loop and place in its own string.

So in the end I end up with:
$PART1 $PART2 $PART3 $FILES
as the command I want to run.

The problem is that when the script is run the command ends up being:
/path/to/command -arg1 -arg2 '/path/to/file1 /path/to/file2'
if there are any spaces in the file names which there often are.

How can I get rid of the single quotes and just have the command be:
/path/to/command -arg1 -arg2 /path/to/file1 /path/to/file2

I am doing this as zsh script on OS X.

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-03-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 541
Stumble this Post!
How is the FILES variable initialized...echo $FILES and post output.

Code:
echo $FILES
Reply With Quote
  #3 (permalink)  
Old 04-03-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
Stumble this Post!
$FILES is created in this loop:

while read line; do
FILES+="${line/ /\ }"
done

So when I input the files: Photo 119.jpg and Photo 136.jpg

echo $FILES
Photo\ 119.jpg Photo\ 136.jpg

It is more that when the command is run instead of a set space delimitated file names there are single quotes around the list of files and so the command thinks they are all one file.

I noticed a similar thread that suggested doing:
echo $(command) | sh
Which did work.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0