LinuxQuestions.org
Review your favorite Linux distribution.
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 09-25-2005, 07:30 PM   #1
Whiteghost
Member
 
Registered: Apr 2003
Distribution: red hat 9.0
Posts: 50

Rep: Reputation: 15
shell script Question


My question is how do i get the c headers in a shell script to work?I have seen some shell script with headers in it.I ope someone can help me with this question.
 
Old 09-25-2005, 08:10 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,336

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"My question is how do i get the c headers in a shell script to work?I have seen some shell script with headers in it."

Shell scripts do not support C headers. The closest thing in script programming to what you describe is functions. Here is some documentation which describes how to use functions in bash script programs.

Bash-Scripting Guide
http://www.tldp.org/LDP/abs/html/

explanation of functions:
http://www.tldp.org/LDP/abs/html/functions.html

function examples:
http://www.tldp.org/LDP/Bash-Beginne...ect_11_02.html

-----------------------
Steve Stites
 
Old 09-25-2005, 09:01 PM   #3
Whiteghost
Member
 
Registered: Apr 2003
Distribution: red hat 9.0
Posts: 50

Original Poster
Rep: Reputation: 15
This what i talking about..


if [ ".`whoami`" != ".root" ]; then
echo "you had to be root to do this!"
exit 1
fi

echo "Now creating socket demon in " $HIDE

echo "#define PORT " $PORT > socketdemon.c
cat >>socketdemon.c <<'EOF'
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
 
Old 09-25-2005, 09:56 PM   #4
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,336

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>"

Any line that begins with a # is a comment and that line is ignored by bash.

------------------------
Steve Stites
 
Old 09-25-2005, 10:05 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
The snippet you posted seems to be a shell script that creates part of a C source file:
Code:
if [ ".`whoami`" != ".root" ]; then
  echo "you had to be root to do this!"
  exit 1
fi
  <= THIS IS PURE SHELL: IT CHECKS TO SEE IF THE CURRENT USER IS "ROOT"

echo "Now creating socket demon in " $HIDE
  <= THIS, TOO, IS PURE SHELL: IT PRINTS OUT THE TEXT ("Now creating..."), FOLLOWED
        BY THE VALUE OF THE SHELL VARIABLE "$HIDE".
        VARIABLES "HIDE" AND "PORT" WERE BOTH  SET SOMEWHERE ELSE
echo "#define PORT " $PORT > socketdemon.c
cat >>socketdemon.c <<'EOF'
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
  <= THIS CAUSES THE REST OF THE SCRIPT TO BE WRITTEN VERBATIM INTO THE
        FILE "SOCKETDEMON.C"
The syntax "<<'EOF'" is called a "here script". You can read more about them in the link jailbait pointed out:
http://www.tldp.org/LDP/abs/html/here-docs.html
 
  


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
Shell Script Question abdul_zu Programming 7 10-06-2005 03:33 AM
Shell Script Question. rvijay Linux - General 2 07-14-2005 06:41 PM
Shell script question... defa0009 Linux - General 7 04-26-2005 08:16 PM
shell script question rrwhite Linux - General 3 09-15-2004 01:01 AM
shell script question Axion Programming 4 07-29-2004 09:51 PM

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

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