Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-29-2008, 03:12 PM
|
#1
|
|
LQ Newbie
Registered: Oct 2008
Location: Kansas, MO
Posts: 9
Rep:
|
I need HELP Writing text to a FILE
I am looking for help on writing to a text file:
Lets say i have a file name text.text and i want to echo out "enter name"
then echo "enter age". The collected information i would like to append it to a file that is created when the function is called:
function addText() {
name=$1
age=$2
folder="$HOME/dir/"
fileName=${folder}dir${age}.txt
tempFile=${folder}films${name}Temp.txt
echo "$name" >> $fileName
}
input:
Enter Name: Raymond
Enter Age: 20
next input:
enter name: ray
enter age: 22
the Output inside the file should look like:
"Raymond", "20"
"ray", "22"
... etc
|
|
|
|
10-29-2008, 03:17 PM
|
#2
|
|
Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 11,805
|
Quote:
Originally Posted by ravi2ray
I am looking for help on writing to a text file:
Lets say i have a file name text.text and i want to echo out "enter name"
then echo "enter age". The collected information i would like to append it to a file that is created when the function is called:
... etc
|
"Captain, sensors indicate a class 4 homework alert ahead...."
|
|
|
|
10-29-2008, 07:06 PM
|
#3
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,999
|
|
|
|
|
10-29-2008, 10:09 PM
|
#4
|
|
LQ Newbie
Registered: Oct 2008
Location: Kansas, MO
Posts: 9
Original Poster
Rep:
|
[QUOTE=TB0ne;3325347]"
Captain, i am working in a project which is almost done. I need to learn how to do things differently in order to become better.
This peace of code works but i don't like it:
echo "$age" >> some.txt
|
|
|
|
10-29-2008, 10:10 PM
|
#5
|
|
LQ Newbie
Registered: Oct 2008
Location: Kansas, MO
Posts: 9
Original Poster
Rep:
|
Quote:
Originally Posted by chrism01
|
Thank you. These links are helpful.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:07 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|