Microsoft
Software
Hardware
Network
Question : Quote string within bash
Hello,
I have the following bash code fragment:
x=0
for i in $(locate $1)
do
dnames[$x]=$(dirname $i)
let x=$x+1
done
Which assigns the output of a locate command into the array dnames one line at a time. It works fine except when the path being returned from locate contains spaces in it, which appears to cause bash to break the input line at the space and put the line in two array locations.
Is there a way to quote the input to dnames to prevent spaces from being interpreted?
Thanks!
Answer : Quote string within bash
IFS='
'
x=0
for i in $(locate $1)
do
dnames[$x]=$(dirname $i)
let x=$x+1
done
or
IFS='
'
dnames=($(locate $1))
Random Solutions
Find competitors top 10 inbound links by highest Google page rank
IIS 6 Crash alot and how to use automatic restart IIS 6
How to remove quotation marks from dsquery results
Using GUIDs as primary key in Mysql innodb and how it affects inner joins
Create Button Macro-- Move to End of Document
How to change the Websphere Apllication Server name
my computer takes forever to open
Exchange server 2007 / windows server 2003- domain authentication question
Timeout error - revisit.
How to refresh parameter list dynamically