LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-22-2010, 10:29 AM   #1
thsuk1
LQ Newbie
 
Registered: Jul 2010
Posts: 2

Rep: Reputation: 0
command in variable


I am making a pipeline of several commands.
This is a part of my shell script.
-----------------------------------
array=(
"mkdir src"
"ls -l | grep tk_ > src/list"
)
len=${#array[*]}

i=0;
while [ $i -lt $len ]; do
echo ${array[$i]}
if !(${array[$i]}); then exit 1; fi;
let i++
done
---------------------------------------
"mkdir src" is working well but "ls -l | grep tk_ > src/list" does not work.
These are error messages.
-----------------------------------------
ls: cannot access |: No such file or directory
ls: cannot access grep: No such file or directory
ls: cannot access tk_: No such file or directory
ls: cannot access >: No such file or directory
ls: cannot access src/list: No such file or directory
-----------------------------------------

How can I solve this problem?

Thanks.
 
Old 07-22-2010, 11:23 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
If you want the commands to work properly, then enclose them like this :

Code:
array=(
$(mkdir src)
$(ls -l | grep tk_ > src/list)
)
However, you won't get the echo you are expecting.
 
Old 07-22-2010, 12:25 PM   #3
thsuk1
LQ Newbie
 
Registered: Jul 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks but,

I think the commands in your code run at the moment when 'array' is created, not in the while loop.

Anyway thanks.

Last edited by thsuk1; 07-22-2010 at 01:49 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can't use variable in mv command john206 Linux - General 13 05-30-2010 06:08 PM
cd command with variable pkacker Programming 8 06-06-2009 02:40 PM
command out to a variable zebrafx Programming 4 02-20-2009 09:12 AM
parsing a variable from here command tostay2003 Programming 5 12-26-2007 08:17 PM
Command & Variable karunesh Programming 5 04-08-2005 06:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration