LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2006, 05:05 AM   #1
ginda
Member
 
Registered: Mar 2004
Distribution: SUSE8.2, 9.2, Knoppix
Posts: 323

Rep: Reputation: 31
how to send shell variable data to a text file


Writting a very very simple shell script, the script contains some variables which i want displayed with a sentence i.e.

hello $1 whats up, what you doing $2
do you like $3

I want to send this data to a text file, i tried

cat << _EOF_


blah blah blah


_EOF_

>> /home/blah/blah.log


any ideas how to achieve this.

Thnaks in advance.
 
Old 06-23-2006, 05:14 AM   #2
prozac
Member
 
Registered: Oct 2005
Location: Australia
Distribution: slackware 12.1
Posts: 753

Rep: Reputation: 32
"hello $1 whats up, what you doing $2" > somefile.txt
"do you like $3" >> somefile.txt
 
Old 06-23-2006, 05:22 AM   #3
ginda
Member
 
Registered: Mar 2004
Distribution: SUSE8.2, 9.2, Knoppix
Posts: 323

Original Poster
Rep: Reputation: 31
would the text be written to file exactley hows its presented in the text, i.e. the overal format, positioning of each sentence.

Thanks
 
Old 06-23-2006, 05:26 AM   #4
prozac
Member
 
Registered: Oct 2005
Location: Australia
Distribution: slackware 12.1
Posts: 753

Rep: Reputation: 32
yes, most probably. just try to format the content as you would like to appear in the text file and re-direct in to the file. its more like try and correct thing.
 
Old 06-23-2006, 05:28 AM   #5
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Try it the other way round:
Code:
cat > file << EOF
 
Old 06-23-2006, 05:31 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Put the redirection on the same line as the cat command:
cat << _EOF_ >> ~/blah.log
 
Old 06-23-2006, 05:45 AM   #7
ginda
Member
 
Registered: Mar 2004
Distribution: SUSE8.2, 9.2, Knoppix
Posts: 323

Original Poster
Rep: Reputation: 31
Thanks guys, really helpful stuff, this is why i love being part of this community
 
Old 06-23-2006, 05:49 AM   #8
prozac
Member
 
Registered: Oct 2005
Location: Australia
Distribution: slackware 12.1
Posts: 753

Rep: Reputation: 32
yeah, we love it too
 
  


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
Saving a text file as a variable and reading it every second in java script mrobertson Programming 4 03-26-2007 08:25 PM
Capturing some data from a file into a variable shiroh_1982 Linux - Newbie 3 06-16-2006 05:59 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
how to cat a text file and save it as a variable mrobertson Programming 37 07-05-2005 08:20 AM
send text to file bash bendeco13 Linux - General 6 11-01-2004 06:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:48 PM.

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