Find the answer to your Linux question:
Results 1 to 3 of 3
I am pretty new to bash scripting so bare with me... I am trying to write a script that will take an input and read it word for word and ...
  1. #1
    Just Joined!
    Join Date
    May 2010
    Location
    United States
    Posts
    2

    bash read input word for word

    I am pretty new to bash scripting so bare with me...

    I am trying to write a script that will take an input and read it word for word and then DO something with it like echo. I have been able to find how to read word for word from a file but I don't know how to do it with input.

    I was looking for something like
    Code:
    #!/bin/bash
    
    INPUT="${1}"
    
    for WORD in ${INPUT}
    do
      echo $WORD
    done
    
    exit 0
    The input would be A-Z a-z 0-9 and have a single space between each word. Any help or direction would be Much appreciated.

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    You have not specified about what you need help. Your script sounds error free. You just have to enclose your single argument in quotes :
    Code:
    your_script.sh "orange and green"
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

  3. #3
    Just Joined!
    Join Date
    May 2010
    Location
    United States
    Posts
    2
    Argh... I had mistyped something in the script and managed to fix it when I typed the code in my forum post.

    Thanks for pointing that out and I will make sure to explain my problem and the error better next time.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...