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
Can't Open Folder; Access Denied
Need simple WAN sollution to connect two small serverless networks.
Rails: Replace HTML with a partial and a collection
How to build small upload script from scratch with progress upload?
segmentation fault when pthread_mutex_lock is called
dbms_jobs
use heirarchical relation for analytical reporting
PHP Include or Require CGI
value of the textbox is not picked by the javascript page.
Find /dev/ location of a mount point in bash script