Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Topics

Recent Status Updates

View All Updates

Photo
- - - - -

Getting input from user


  • Please log in to reply
3 replies to this topic

#1 restin84

restin84

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 88 posts
  • Programming Language:C, Java, C++
  • Learning:PHP, Python, Assembly

Posted 24 September 2011 - 12:08 PM

I have an assignment to write a script which requires the user to input four lines of text. Those four lines of text will be manipulated in various ways. Is there a way to save these for lines of text before I save them in a file? Should I use the "read" command?
  • 0

#2 visionviper

visionviper

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 25 September 2011 - 12:40 PM

What language? Or are you just making a shell script?
  • 0

#3 restin84

restin84

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 88 posts
  • Programming Language:C, Java, C++
  • Learning:PHP, Python, Assembly

Posted 27 September 2011 - 09:37 AM

Yes it is just a shell script
  • 0

#4 DarkLordCthulhu

DarkLordCthulhu

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 422 posts
  • Location:The bash shell
  • Programming Language:C, JavaScript, Bash, Others
  • Learning:Ruby, Others

Posted 04 October 2011 - 04:35 AM

For a shell script, you should use the read command four times and save each line in a variable.

read line1;
read line2;
read line3;
read line4;

There's no need to declare or initialize the variables. read declares them implicitly.
  • 0
Programming is a journey, not a destination.




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download