LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-05-2008, 05:47 PM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Rep: Reputation: 39
Correct syntax for adding text to an existing file


Hi there --

I have a script that creates a .forward file in a newly created user's home directory. The syntax that I am using is the following:

Code:
# Create the .forward file in the user's home directory.
       /bin/touch "/home/$username/.forward"
I want to have the script insert the user's e-mail address into the .forward file that was just created. The command syntax that I thought of using is the following:

Code:
# Insert the user's e-mail address into the .forward file.
       /bin/cat $username.cox.net > "/home/$username/.forward"
Will this syntax work, or is there another that it should be done? Thanks.
 
Old 01-05-2008, 05:53 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You want to use >> to append, i.e. "cat $username.cox.net >> /home/$username/.forward".
 
Old 01-05-2008, 05:57 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,131

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
New file, shouldn't matter - either will do just as well.
 
Old 01-05-2008, 05:58 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I'd use echo instead of cat
Code:
echo $username.cox.net >> "/home/$username/.forward"
since cat would look for a file called $username.cox.net.
 
Old 01-05-2008, 06:36 PM   #5
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
Thank-you all for the help. I opted for the echo command syntax, and that proved to work.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding text to places in a file helptonewbie Programming 6 10-05-2007 06:09 PM
adding text to a file from console rob_xx17 Linux - General 8 02-10-2006 07:16 AM
adding text to lines in a file tpreitano Linux - General 2 10-04-2005 09:30 AM
adding text file browser Linux - General 5 09-09-2005 09:10 PM
correct syntax for a canonical file? rioguia Linux - Software 1 11-04-2003 02:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration