LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-28-2007, 04:14 AM   #1
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Rep: Reputation: 16
cat and end of file statements


After discovering that I could create files with the cat command like this:
Quote:
#!/bin/bash
cat >file.txt <<_ACEOF
blabla
_ACEOF
I was wondering what the "_ACEOF" does.
I tried replacing it with "EOF" and it also works.

So why use _ACEOF instead or any other EOF statement?
 
Old 06-28-2007, 04:24 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
There's no reason--it's completely arbitrary.

That said, I imagine the Autoconf developers deliberately chose to use _ACEOF to avoid problems. It's common for compiler developers to use an underscore as a prefix for certain compiler directives. Doing so is an attempt to create unique identifiers without using words/phrases a programmer might like. For instance "_DEBUG" or "__DEBUG" might be used by the compiler because it's extremely unlikely that a programmer would want to use that as a variable or function name. The autoconf developers are likely following that naming convention.

Also, the "AC" likely stands for AutoConf. Another layer to prevent a naming conflict.

If I'm not mistaken, the autoconf package allows the developer to include shell scripts of his/her own as part of the configuration process. Assuming that is the case, you can see why the autoconf developers wanted to avoid a naming conflict. Using "EOF" in way you demonstrate is common, and might easily be used in a script given to autoconf by the developer. There would be a very real risk that the configure script would go bonkers if the autoconf-generated scripts used EOF while the developer-included scripts used EOF as well.

Last edited by Dark_Helmet; 06-28-2007 at 04:52 AM.
 
1 members found this post helpful.
Old 06-28-2007, 04:29 AM   #3
[KIA]aze
Member
 
Registered: Jun 2006
Distribution: Debian, Ubuntu, Windows XP
Posts: 146

Original Poster
Rep: Reputation: 16
And why is there sometimes "cat <<\_ACEOF"?

I also currently have a problem in my script:
The cat command seems to add everything in the script coming after the _ACEOF to the created file instead of considering it as part of the script.
I'm trying to create a shellscript that creates a file if it doesn't exist.

edit: Just solved that problem: There was a space after "_ACEOF".
I still don't see why "\_ACEOF" is used. Also for uniqueness?

Last edited by [KIA]aze; 06-28-2007 at 04:33 AM.
 
  


Reply


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
cat file but don't quit Ephracis Linux - Software 2 08-26-2006 12:56 AM
filesize limit on 'cat $file | sed > $file' drkstr Linux - Software 2 07-10-2006 02:47 AM
trying to redirect text to a file to cat at later point. says file doesn't exist. dr_zayus69 Programming 1 10-02-2005 08:10 AM
Cat with Binary File? Xaque208 Linux - General 1 12-06-2004 07:59 PM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 02:41 AM

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

All times are GMT -5. The time now is 09:01 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