LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-07-2003, 05:12 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Bug in C code


root:~# gcc -o test2 test2.c
root:~# ./test2
sh: -c: line 3: syntax error: unexpected end of file

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

main()
{
system("for i in `cat /etc/samba/smbpasswd|awk '{split($0,a,\":\"); "
"if ((substr(a[1],1,1)!=\"#\") && (a[1]!=\"admin\")) print a[1]}'` "
"do "
"echo -n -e \"SMBUser\t\t\t$i\t\t\"`du -ks /home/$i | "
"awk '{print (($1*1024)/1000000)}'`\"\n\" "
"done");
}
 
Old 07-07-2003, 05:53 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
You can't concatenate strings like that. You will have to put all of the commands into a single string.

man strcat

Also, it looks like you're trying to simulate hitting the "enter" key by ending the string. The shell/system call doesn't care about newlines; it ignores them. They're only provided as a means to make it more readable to people. To see what I mean, type out that sequence of commands like you would normally do at the command prompt. Execute it, and then hit the up arrow. Bash prints out the command all on a single line. That is what you will need to make your string look like when you feed it to the system command.
 
Old 07-07-2003, 05:59 PM   #3
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
why cant you concatenate strings like that? thats the way to continue strings over more than 1 line in C. the error i think is in the shell commands, instead of calling system print out the string and see of it prints what you actually mean to execute.
 
Old 07-07-2003, 06:06 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
You're probably right kev. I just don't do it that way. I get "set in my ways" and if I see something that doesn't fit my coding style, I get antsy...

I'll go back into my little corner now...
 
  


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
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
Possible gamepad code bug? Requesting testers. Dr Twox Linux - Hardware 1 07-09-2004 08:24 PM
Free86 bug or nVidia bug?? ProtoformX Linux - Software 2 05-12-2004 02:38 AM
Bug in MS Access Code Linh Programming 2 10-09-2003 02:47 PM
Bug in c code calling bash code Linh Programming 11 08-12-2003 04:27 AM

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

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