LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-20-2012, 09:33 AM   #1
ajayyadavmca
LQ Newbie
 
Registered: Dec 2006
Posts: 28

Rep: Reputation: 0
shell script array problem


hi, this could be simple one.
I have one file which contains variables like..

Code:
...
files=( /root/b/*.txt /root/xyz.txt)
..
now I have script which reads above file.

Code:
....
if [[ "${#files[@]}" != 0 ]]
then
    for i in "${files[@]}"; do echo $i; done
else
    echo "not correct"
fi
....
suppose /root/b folder has 5 .txt files than array "files" gets 5 + 1(xyz.txt)=6 values.

what i want as out put is:
same what is written there (with * character) that means array should have just 2 elements like:
Code:
/root/b/*.txt 
/root/xyz.txt
So * should be there and should not get expanded.

Thanks, Ajay
 
Old 06-20-2012, 10:14 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
So put single quotes around it and it won't get expanded.
 
Old 06-21-2012, 01:41 AM   #3
ajayyadavmca
LQ Newbie
 
Registered: Dec 2006
Posts: 28

Original Poster
Rep: Reputation: 0
Thanks, this is same what i did.
 
Old 06-21-2012, 09:35 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Please mark as SOLVED once you have a solution.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Array in Shell Script dnoob Programming 13 10-20-2013 04:25 PM
array in shell script Abid Malik Programming 2 10-16-2010 01:49 PM
[SOLVED] shell script help: copying directory list into an array and then accessing the array richman1234 Linux - Newbie 6 07-25-2010 11:19 PM
Array shell script pooppp Linux - Networking 6 08-01-2008 08:37 AM
shell script array problem rche3252 Programming 1 10-08-2003 11:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:44 AM.

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