Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

[SOLVED] Bash - Arrays and Delimeters

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
3 posts • Page 1 of 1
Author
Message
djscribble
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 116
Joined: Wed Aug 03, 2005 9:23 pm

[SOLVED] Bash - Arrays and Delimeters

  • Quote

Post by djscribble » Sun Feb 15, 2009 8:22 pm

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: Select all

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

Code: Select all

./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.
Top
easy target
Tux's lil' helper
Tux's lil' helper
Posts: 134
Joined: Wed Jan 09, 2008 2:45 pm

  • Quote

Post by easy target » Sun Feb 15, 2009 8:53 pm

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

Example code:

Code: Select all

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

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

echo ${array[0]}
echo ${array[1]}
Top
djscribble
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 116
Joined: Wed Aug 03, 2005 9:23 pm

  • Quote

Post by djscribble » Mon Feb 16, 2009 12:48 am

works great -- THANKS!!!
Top
Post Reply

3 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic