Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-17-2012, 07:22 AM   #1
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 674

Rep: Reputation: 34
bash : getting text into file


I need to create file 121212-flb with first line of text [121212-flb] with bash script :

touch /etc/addons/$FLBfile

makeFLB=$(/etc/addons/$FLBfile << $FLBheading)
My command :
[root@p2 admin]# sh 121212

Output :
Quote: line 9: warning: here-document at line 9 delimited by end-of-file (wanted `$FLBheading') line 8: warning: here-document at line 8 delimited by end-of-file (wanted `$FLBheading') line 8: /etc/addons/121212-flb: Permission denied
File is created, but without text inside.
Old 03-17-2012, 07:34 AM   #2
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 674

Original Poster
Rep: Reputation: 34
Solved : makeFLB=$(echo $FLBheading > /etc/addons/$FLBfile)
Old 03-17-2012, 02:21 PM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,846

Rep: Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007Reputation: 2007
No, this doesn't work the way you think it does:

makeFLB=$(echo $FLBheading > /etc/addons/$FLBfile)
"variable=$( command )" sets the value of variable to the standard out of command. But "command > filename" redirects the stdout of command into filename, and so there's no output available to set the variable with.

Your makeFLB variable will always come out empty.

So to start with, do the redirection on its own, without the variable setting:
echo "$FLBheading" > "/etc/addons/$FLBfile"
Then tell us what the makeFLB variable is supposed to contain, so we can help you set it properly.

(P.S.: You also don't need to touch the filename first. > and >> will create the file if necessary.)

Next, for the record, your first error message resulted from here:

makeFLB=$(/etc/addons/$FLBfile << $FLBheading)
The section inside $() is considered a separate command environment, but here there's no executable command name inside it; only a filename. Since file redirections like "<<" only work in the context of executed commands, in this case it's instead treated as the beginning of a here document.

And since there's no matching closing string for the heredoc in the script, it chokes and coughs up the error given.

Last edited by David the H.; 03-17-2012 at 02:28 PM. Reason: fixes


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Bash command to 'cut' text into another text file & modifying text. velgasius Programming 4 10-17-2011 05:55 AM
variable from text file bash drumbum Programming 1 07-30-2009 10:50 AM
bash script to create text in a file or replace value of text if already exists knightto Linux - Newbie 5 09-11-2008 12:13 AM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 12:55 PM
send text to file bash bendeco13 Linux - General 6 11-01-2004 07:26 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:44 AM.

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