Skip to main content
Fix misspelling of the word 'sentence'
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

How can I take input from read, split the words up by spaces, and then put those words into an array?

What I want is:

$ read sentence
this is a sentence
$ echo $sentence[1]
this
$ echo $sentence[2]
is
(and so on...)

I'm using this to process englishEnglish sentences for a text adventure.

How can I take input from read, split the words up by spaces, and then put those words into an array?

What I want is:

$ read sentence
this is a sentence
$ echo $sentence[1]
this
$ echo $sentence[2]
is
(and so on...)

I'm using this to process english sentences for a text adventure.

How can I take input from read, split the words up by spaces, and then put those words into an array?

What I want is:

$ read sentence
this is a sentence
$ echo $sentence[1]
this
$ echo $sentence[2]
is
(and so on...)

I'm using this to process English sentences for a text adventure.

How can I take input from read and, split the words up by spaces, and then put those words into an array?

What I want is:

$ read scentencesentence
this is a senctencesentence
$ echo $scentence[1]$sentence[1]
this
$ echo $scentence[2]$sentence[2]
is
(and so on...)

I'm using this to process english scentencessentences for a text adventure.

How can I take input from read and split the words up by spaces, and then put those words into an array?

What I want is:

$ read scentence
this is a senctence
$ echo $scentence[1]
this
$ echo $scentence[2]
is
(and so on...)

I'm using this to process english scentences for a text adventure.

How can I take input from read, split the words up by spaces, and then put those words into an array?

What I want is:

$ read sentence
this is a sentence
$ echo $sentence[1]
this
$ echo $sentence[2]
is
(and so on...)

I'm using this to process english sentences for a text adventure.

edited tags
Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
Source Link
SpecialBomb
  • 2k
  • 10
  • 28
  • 37
Loading