Results 1 to 8 of 8

Thread: [SOLVED] Take user input and send it to a file

  1. #1
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    [SOLVED] Take user input and send it to a file

    Hi Everyone,

    I want to try an experiment where I take a user's input (name) and then put it in a text file. Here's my example:

    #!/bin/bash

    set verbose

    echo -n "What is your name?

    Please Enter Here: "
    read $name

    ????? >> /home/my_name/Desktop/testing.txt

    fi

    unset verbose


    The ????? is the part I don't know.

    If the file exists, I want to append it and if not, I want this to create it and then write it.

    I've lost some of my reference material and am having problems remembering how to do this.

    Thanks for any help you can provide...

  2. #2
    Join Date
    Jun 2007
    Location
    Edinburgh Scotland
    Beans
    260
    Distro
    Xubuntu 11.04 Natty Narwhal

    Re: Take user input and send it to a file

    ?????? = echo
    ie echo "$name" > file.txt
    I laughed, I cried, I jumped with joy. I was here before Killroy. 8)

  3. #3
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Take user input and send it to a file

    I did that and it didn't work... let me try again now...

  4. #4
    Join Date
    Jun 2007
    Location
    Edinburgh Scotland
    Beans
    260
    Distro
    Xubuntu 11.04 Natty Narwhal

    Re: Take user input and send it to a file

    Quote Originally Posted by mdpalow View Post
    I did that and it didn't work... let me try again now...
    Sorry, missed the 2nd line 1st time - added it as an edit
    I laughed, I cried, I jumped with joy. I was here before Killroy. 8)

  5. #5
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Take user input and send it to a file

    for some reason it won't store the $name and then pass it to the file. If I put regular text around $name it puts the text in file, but leave out the $name

    #!/bin/bash

    set verbose

    echo -n "what is your name?

    Please Enter Here: "
    read $name

    echo "$name" >> /home/$USER/Desktop/testing.txt


    unset verbose

  6. #6
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Take user input and send it to a file

    OMG... I found it.... Can't believe I did that...

    there's no $ after read.. it's not "read $name" it's just "read name"

    Thanks...

  7. #7
    Join Date
    Jun 2007
    Location
    Edinburgh Scotland
    Beans
    260
    Distro
    Xubuntu 11.04 Natty Narwhal

    Re: [SOLVED] Take user input and send it to a file

    np. I didn't see it either
    I laughed, I cried, I jumped with joy. I was here before Killroy. 8)

  8. #8
    Join Date
    Oct 2007
    Beans
    42

    Re: Take user input and send it to a file

    I know a little little shell scripting. I have to learn C++ or shell scripting because I have to write a small programme using the above language for a friend . I followed your example. But nothing is written to the testing.txt. The file was opened. Nothing could be read with human eyes when I vi the file. The last line reads “testing.txt”4 lines, 4 characters.

    Could anyone tell me what is wrong with my ubuntu set- up in not writing the name to the file properly?

Bookmarks

Posting Permissions

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