LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-24-2003, 12:17 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Calling long BASH code within a C program


Error occur when running a program that Call a long BASH code within a C program

root:~# ./test-small-network-sh
sh: -c: line 2: syntax error: unexpected end of file
sh: -c: line 2: syntax error: unexpected end of file
sh: -c: line 2: syntax error: unexpected end of file
sh: -c: line 2: syntax error: unexpected end of file
sh: -c: line 2: syntax error: unexpected end of file

====================================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <signal.h>


/********************************/

int main()
{
system("if [[""$quotastat"" == """"]]; then echo ""off"" > /var/apache/quota.status fi");

system("if [""$quotastat"" == ""on""]; then /sbin/quotaon -v /home else /sbin/quotaoff /home fi");

system("if [[""$verify"" == """"]]; then "
"/usr/local/sbin/test.sh "
"echo ""done"" > /var/apache/verify "
"fi");


system("if [""$snmpvar"" == """"]; then "
"cp /usr/local/sbin/snmpd.conf /etc "
"fi");


system("if [""$sysparam"" == """"]; then cp /usr/local/sbin/sysparam.conf /etc fi");
}
 
Old 06-24-2003, 12:29 PM   #2
jvannucci
Member
 
Registered: Jan 2003
Location: Connecticut, US
Distribution: Red Hat 9.0
Posts: 98

Rep: Reputation: 15
Try escaping double quotes, not doubling them ( \" ).
 
Old 06-24-2003, 12:40 PM   #3
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
Use \" instead of double quote, but the error is still there

I use \" instead of double quote "", but the error is still there

root:~# ./test-small-network-sh
sh: -c: line 2: syntax error: unexpected end of file

========================================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <signal.h>

/*************************************/

int main()
{
system("if [[\"$quotastat\" == \"\"]]; then echo \"off\" > /var/apache/quota.status fi");
}
 
Old 06-24-2003, 12:59 PM   #4
jvannucci
Member
 
Registered: Jan 2003
Location: Connecticut, US
Distribution: Red Hat 9.0
Posts: 98

Rep: Reputation: 15
Add a semicolon before 'fi'. Also make sure you have spaces around your [[ ]]. In other words, make sure it works directly in shell first before trying to make it callable from C.
 
Old 06-24-2003, 01:41 PM   #5
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
I did as suggested

Add a semicolon before 'fi'. Also make sure you have spaces around your [[ ]]. It worked !!

=========================================
#include <stdio.h>

int main()
{
system("if [[ \"$quotastat\" == \"\" ]]; "
"then "
"echo \"off\" > /var/apache/quota.status; "
"fi");
}
=======================================

jvannucci got it right !!!

and THANK YOU EVERYONE FOR PARTICIPATING.

Last edited by Linh; 06-24-2003 at 02:00 PM.
 
  


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
Who-is-calling-Who (bash programming) kaone Programming 2 09-19-2005 10:31 AM
calling external applications in your c++ code drisay Programming 2 01-25-2005 12:41 PM
Bug in c code calling bash code Linh Programming 11 08-12-2003 04:27 AM
C program code calling a Linux system command Linh Programming 1 06-05-2003 01:44 PM
c++ calling bash? adam_boz Programming 4 10-23-2002 12:23 PM

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

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