ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
when bash is run interactively, there's often some sort of terminal emulation session associated with it; when the terminal emulator is closed, the bash session ends.
With your test, the input to the bash is closed after the "aaa" is sent to bash.
It will stay open, if instead it is tested like this:
Code:
while read a_line; do echo $a_line; done | test_shell
Hi!
Give the input:
[buf]: Hi!
Shell is still open, but C program won't echo any more lines because it is not looping, looking for additional input.
I compiled your test_shell.c program, and the above is the actual output, the shell session stays open.
But I do have to wonder what you think you will be able to accomplish with the C program, exactly as it is. The C program isn't going to be able to read any more input, unless it loops, or some such, looking for more input.
root@kali:b="aaaaaa";while read a_line; do printf $b; echo $a_line;b=''; done | ./test_shell
Give the input:
[buf]: aaaaaa
whoami
printf: usage: printf [-v var] format [arguments]
root
cat test_shell.c
printf: usage: printf [-v var] format [arguments]
#include <stdlib.h>
#include <stdio.h>
/*
gcc -m32 -o test_shell test_shell.c
*/
int main()
{...........................
The C program was a simplified version I wrote to be easier to explain what I need to do.
The idea was the I had to feed the input for fgets from command line so I can format it properly, there were some dodgy chars I had to write them in hex .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.