|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
running a C program that Call a long BASH code
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"); } |
|
#2
|
||||
|
||||
|
Er.. you should be escaping those double quotes " with a \, something like this \", not doubled quotes "".
|
|
#3
|
|||
|
|||
|
Use \" instead of double quote and still have error
I use \" instead of double quote "" and still have error
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"); } |
|
#4
|
||||
|
||||
|
My question is why are you trying to execute bash commands through the system function?
Why not create a bash script file that executes these commands and call that script from the system function? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > running a C program that Call a long BASH code |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|