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
SQL Server 2000, 2005 and 2008 + shrink
Writing results of a VBA driven Pass-Trhough Query to an Access table
Sybase SQL Anywhere ISQL from command line
in Bash's Sort, how do I sort by a second or third field ?
How to get outlook express back on my computer
Error in ghost image
When attempting to Modify a VB 6.0 Program that uses Crystal Reports 6.0 the Crystal Report fails to get Loaded
networking xp and vista- xp seeing vista but vista not seeing xp
difference between RE-INDEXING and INDEX-DeFragging
Check if current user is administrator or limited user