Running a String as a command, zsh.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a String as a command, zsh.
# 1  
Old 04-03-2008
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.
# 2  
Old 04-03-2008
How is the FILES variable initialized...echo $FILES and post output.

Code:
echo $FILES

# 3  
Old 04-03-2008
$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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Another one line command where I'd like to determine if Ubuntu or Red Hat when running command

Hello Forum, I'm making very good progress on my report thanks to the very helpful people on this forum. I've been able to successfully create my report for my Red Hat servers. But I do have a few ubuntu servers in the mix and I'd like to capture some data from them when an ssh connection is... (8 Replies)
Discussion started by: greavette
8 Replies

2. Shell Programming and Scripting

Problem reading terminal response string from Zsh

Note: This posting is related to my posting at bash - Reading answer to control string sent to xterm - Stack Overflow , but I could get there a solution only for bash. I can use that solution, but for curiosity, I wonder, whether I could do this in Zsh as well. The problem is to send a (Posix-)... (6 Replies)
Discussion started by: rovf
6 Replies

3. AIX

I'm facing problem with rpm command, when running the command and appears this error:

exec(): 0509-036 Cannot load program /usr/opt/freeware/bin/rpm because of the following errors: 0509-022 Cannot load module /opt/freeware/lib/libintl.a(libintl.so.1). 0509-150 Dependent module /opt/freeware/lib/libiconv.a(shr4.o) could not be loaded. 0509-152 Member... (4 Replies)
Discussion started by: Ohmkar
4 Replies

4. Shell Programming and Scripting

Run bash command inside zsh script

Hi, I would like to run following code in bash inside a zsh script. (In this case is output unfortunately very different if you run it in zsh). I tried to put "bash" in front of the code but I obtained following error message "bash: do: No such file or directory " eve though I merged the whole... (7 Replies)
Discussion started by: kamcamonty
7 Replies

5. Shell Programming and Scripting

Command to check only Autosys running jobs with autorep like command

Hi, Is there any specific command to use to check only say Running jobs via autorep or similar command for Autosys? (0 Replies)
Discussion started by: sidnow
0 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

8. Shell Programming and Scripting

running zsh command in tcsh

Hi all is there a way to run zsh commands in a tcsh shell thanks (3 Replies)
Discussion started by: ab52
3 Replies

9. Shell Programming and Scripting

equivalent of ptree command in zsh

ptree command is not working in zsh. Could anyone let me know the equivalent of ptree command in zsh. (3 Replies)
Discussion started by: dhams
3 Replies

10. SuSE

inconsistent ls command display at the command prompt & running as a cron job

Sir, I using the following commands in a file (part of a bigger script): #!/bin/bash cd /opt/oracle/bin ls -lt | tail -1 | awk '{print $6}' >> /tmp/ramb.out If I run this from the command prompt the result is: 2007-05-16 if I run it as a cron job then... (5 Replies)
Discussion started by: rajranibl
5 Replies
Login or Register to Ask a Question