View previous topic :: View next topic |
Author |
Message |
djscribble Tux's lil' helper
Joined: 03 Aug 2005 Posts: 116
|
Posted: Sun Feb 15, 2009 8:22 pm Post subject: [SOLVED] Bash - Arrays and Delimeters |
|
|
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 |
|
|
easy target Tux's lil' helper
Joined: 09 Jan 2008 Posts: 134
|
Posted: Sun Feb 15, 2009 8:53 pm Post subject: |
|
|
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 |
|
|
djscribble Tux's lil' helper
Joined: 03 Aug 2005 Posts: 116
|
Posted: Mon Feb 16, 2009 12:48 am Post subject: |
|
|
works great -- THANKS!!! |
|
Back to top |
|
|
|