LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   C code for a mini shell (https://www.linuxquestions.org/questions/linux-newbie-8/c-code-for-a-mini-shell-4175518569/)

ramxo 09-14-2014 01:46 PM

C code for a mini shell
 
my Assignment is to
write a a program which takes input from user .
then modify the program enabling to check the contents of a directory now modify it to check if the input string is present in the \bin or \sbin directory

btmiller 09-14-2014 01:50 PM

Great - what have you tried so far and what problems are you having? No one on this forum is going to do your homework for you, but we may be able to help if you give it an honest effort and run into trouble. One thing to note, the *nix path separator is a forward slash, not a backslash as in DOS, so it's not \bin and \sbin but rather /bin and /sbin.

ramxo 09-14-2014 01:59 PM

i am completely new to linux C programming and i m searching how can i start , just found this forum and registered here . maybe someone will help me getting starts . and sorry for the slash as you guys can understand how it feels when you dont have a clue about the thing you will have to work with .

jkirchner 09-14-2014 02:49 PM

Have you read through the rules for the forums? This is one of the points:

Quote:

Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.
Read the rules here.

Like btmiller said, post what you have tried first and then we can help. Noone will write it for you.

metaschima 09-14-2014 04:09 PM

The getting user input is easy, you should already know how to do that, and you probably have more details on exactly what is required.

As for the directory listing, this is not part of the standard C library, so you will either have to:
1) Use the 'system()' function to execute the right command.
http://www.cplusplus.com/reference/cstdlib/system/
2) Use glib:
https://developer.gnome.org/glib/2.4...tml#g-dir-open

btmiller 09-14-2014 04:19 PM

Usually a "real" Unix shell like bash would use stat(2) or one of its variants to check and see if a file exists somewhere in its $PATH.

To the OP - if this is homework you must be taking a class. Did your lectures not cover what you need to know to complete the assignment? If not, maybe you should seek clarification from your professor...

keefaz 09-14-2014 06:03 PM

Maybe glibc opendir(), readdir()..?


All times are GMT -5. The time now is 05:11 AM.