Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Bash - Arrays and Delimeters
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
djscribble
Tux's lil' helper
Tux's lil' helper


Joined: 03 Aug 2005
Posts: 116

PostPosted: Sun Feb 15, 2009 8:22 pm    Post subject: [SOLVED] Bash - Arrays and Delimeters Reply with quote

Greetings,

I am working on a script and am having problems changing the delimeter that bash is using for arrays. Here is my sample/experiment script:

Code:
#!/bin/bash
IFS='|'
array=(one two|three four)
echo ${array[0]}
echo ${array[1]}


Here is the output:
Code:
./test: line 3: syntax error near unexpected token `|'
./test: line 3: `array=(one two|three four)'



Any thoughts on how i might be able to make this work?

thanks!


Last edited by djscribble on Mon Feb 16, 2009 12:48 am; edited 1 time in total
Back to top
View user's profile Send private message
easy target
Tux's lil' helper
Tux's lil' helper


Joined: 09 Jan 2008
Posts: 134

PostPosted: Sun Feb 15, 2009 8:53 pm    Post subject: Reply with quote

bash thinks that | is a pipe (or else...). You have to surround it with "".

Example code:

Code:
#!/bin/bash
str="one two|three four"

tmp=$IFS
IFS="|"
declare -a array=($str)
IFS=$tmp

echo ${array[0]}
echo ${array[1]}
Back to top
View user's profile Send private message
djscribble
Tux's lil' helper
Tux's lil' helper


Joined: 03 Aug 2005
Posts: 116

PostPosted: Mon Feb 16, 2009 12:48 am    Post subject: Reply with quote

works great -- THANKS!!!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum