SlideShare a Scribd company logo
Hello!
I'm trying to build a command line interpreter simulator using C programming language,
working in the linux environment. I don't want to get in to designing the whole thing, I just want
a little help with a particular problem. This particular problem is how do I write a line or lines in
C that will run a command as if I had typed it in the terminal? More specifically, the command
I'm trying to run is "help." The command that shows all available commands.
So for example, I want to simulate the "ls" command, the command that lists the content of the
current directory. I would go into my editor and type this:
#include
#include
int main()
{
system("ls");
return 0;
}
Now if I go into the terminal, compile that program and run it, it'll display the content of the
current directory as would simply typing in "ls" in the terminal. The problem is, I can't manage
to do the same for the "help" command. After researching a bit, I've found that the sh shell is
looking in /bin and /usr/bin to execute "help." However, that command is in neither directory
and will ultimately let me know that the command is "not found." If it's not in the earlier
mentioned directories, then where could it be? Is it even possible to run "help" within a C
program?
Sorry if it's a little long, I just wanted to be as clear as I can be. Any help would be greatly
appreciated!
Solution
you need to us ,
system ("/bin/ls");
Below is the update
*******************************************************
Also , you can use the below program to list the directories,

More Related Content

PDF
Hello. I was wondering if I could get some help on this C programmin.pdf
PPT
101 3.1 gnu and unix commands
PDF
Linux fundamental - Chap 00 shell
PDF
The structure of Linux - Introduction to Linux for bioinformatics
PDF
60761 linux
PDF
PPT
101 3.1 gnu and unix commands v4
DOCX
Write a C program called pross-c to implement the UNIX-Linux equivalen.docx
Hello. I was wondering if I could get some help on this C programmin.pdf
101 3.1 gnu and unix commands
Linux fundamental - Chap 00 shell
The structure of Linux - Introduction to Linux for bioinformatics
60761 linux
101 3.1 gnu and unix commands v4
Write a C program called pross-c to implement the UNIX-Linux equivalen.docx

Similar to Hello!Im trying to build a command line interpreter simulator us.pdf (20)

PPT
3.1 gnu and unix commands v4
PDF
Introduction to the linux command line.pdf
PDF
Os lab final
PDF
Linux shell ggsipu-lug
DOCX
BACKGROUND A shell provides a command-line interface for users. I.docx
PDF
Course 102: Lecture 10: Learning About the Shell
PDF
Linux shell
PDF
Unix practical file
PPT
HISTORY, TYPES OF EMBEDDED LINUX, COMMANDS,
PDF
Shell intro
PDF
Shell intro
PDF
Course 102: Lecture 8: Composite Commands
PPTX
Introduction to-linux
PPT
Linux commands
PPTX
OS-Module 2 Linux Programming Important topics
PPT
Linux_C_LabBasics.ppt
PDF
Scripting and the shell in LINUX
PDF
Session3
DOCX
#include string.h#include stdlib.h#include systypes.h.docx
PDF
Shell intro
3.1 gnu and unix commands v4
Introduction to the linux command line.pdf
Os lab final
Linux shell ggsipu-lug
BACKGROUND A shell provides a command-line interface for users. I.docx
Course 102: Lecture 10: Learning About the Shell
Linux shell
Unix practical file
HISTORY, TYPES OF EMBEDDED LINUX, COMMANDS,
Shell intro
Shell intro
Course 102: Lecture 8: Composite Commands
Introduction to-linux
Linux commands
OS-Module 2 Linux Programming Important topics
Linux_C_LabBasics.ppt
Scripting and the shell in LINUX
Session3
#include string.h#include stdlib.h#include systypes.h.docx
Shell intro
Ad

More from forecastfashions (20)

PDF
Identify the organ labelled 3.liverstomacht h e mesenteryjej.pdf
PDF
Fahrenheit ToCelsiusValue.java Done Program name Fahrenheit To Celsiu.pdf
PDF
Explain the relationship between three aspects of science hypothesi.pdf
PDF
Did BP respond to the oil spill in a manner that was appropriate to .pdf
PDF
Consider the subset S = {0, 2, 4, 6, 8, 10, 12} of Z14Z. (a) Show t.pdf
PDF
Assignment Description When dealing with a performance improvement .pdf
PDF
Answer ALL 2 QUESTIONS please.... You configured several time settin.pdf
PDF
A heritability of body weight of 0.4 means that body weight is deter.pdf
PDF
After reading the Cultural Competency Module, reflect on your own co.pdf
PDF
A variable that consists of indivisible categories with no other sco.pdf
PDF
C++ BinaryTree Help Creating main function for Trees...Here are .pdf
PDF
Write a short essay explaining the four primary groups of production.pdf
PDF
Why didnt the government just arrange to have excess food commodit.pdf
PDF
Where is Virtual Reality going, and where would it be 20 yearsS.pdf
PDF
What is the negative side to overusing technical communication tools.pdf
PDF
What is the method of action of aldehydes They damage proteins .pdf
PDF
What are rubisco and RuBP And what do they do Briefly list 4 simil.pdf
PDF
Virtual Machines Discuss what are the new innovation today in this .pdf
PDF
Using Java, please write the program for the following prompt in the.pdf
PDF
True or FalseBecause IPsec is located in the IP layer, when it is.pdf
Identify the organ labelled 3.liverstomacht h e mesenteryjej.pdf
Fahrenheit ToCelsiusValue.java Done Program name Fahrenheit To Celsiu.pdf
Explain the relationship between three aspects of science hypothesi.pdf
Did BP respond to the oil spill in a manner that was appropriate to .pdf
Consider the subset S = {0, 2, 4, 6, 8, 10, 12} of Z14Z. (a) Show t.pdf
Assignment Description When dealing with a performance improvement .pdf
Answer ALL 2 QUESTIONS please.... You configured several time settin.pdf
A heritability of body weight of 0.4 means that body weight is deter.pdf
After reading the Cultural Competency Module, reflect on your own co.pdf
A variable that consists of indivisible categories with no other sco.pdf
C++ BinaryTree Help Creating main function for Trees...Here are .pdf
Write a short essay explaining the four primary groups of production.pdf
Why didnt the government just arrange to have excess food commodit.pdf
Where is Virtual Reality going, and where would it be 20 yearsS.pdf
What is the negative side to overusing technical communication tools.pdf
What is the method of action of aldehydes They damage proteins .pdf
What are rubisco and RuBP And what do they do Briefly list 4 simil.pdf
Virtual Machines Discuss what are the new innovation today in this .pdf
Using Java, please write the program for the following prompt in the.pdf
True or FalseBecause IPsec is located in the IP layer, when it is.pdf
Ad

Recently uploaded (20)

PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
Computing-Curriculum for Schools in Ghana
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Institutional Correction lecture only . . .
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Cell Types and Its function , kingdom of life
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Complications of Minimal Access Surgery at WLH
Computing-Curriculum for Schools in Ghana
102 student loan defaulters named and shamed – Is someone you know on the list?
GDM (1) (1).pptx small presentation for students
Module 4: Burden of Disease Tutorial Slides S2 2025
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
202450812 BayCHI UCSC-SV 20250812 v17.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
Institutional Correction lecture only . . .

Hello!Im trying to build a command line interpreter simulator us.pdf

  • 1. Hello! I'm trying to build a command line interpreter simulator using C programming language, working in the linux environment. I don't want to get in to designing the whole thing, I just want a little help with a particular problem. This particular problem is how do I write a line or lines in C that will run a command as if I had typed it in the terminal? More specifically, the command I'm trying to run is "help." The command that shows all available commands. So for example, I want to simulate the "ls" command, the command that lists the content of the current directory. I would go into my editor and type this: #include #include int main() { system("ls"); return 0; } Now if I go into the terminal, compile that program and run it, it'll display the content of the current directory as would simply typing in "ls" in the terminal. The problem is, I can't manage to do the same for the "help" command. After researching a bit, I've found that the sh shell is looking in /bin and /usr/bin to execute "help." However, that command is in neither directory and will ultimately let me know that the command is "not found." If it's not in the earlier mentioned directories, then where could it be? Is it even possible to run "help" within a C program? Sorry if it's a little long, I just wanted to be as clear as I can be. Any help would be greatly appreciated! Solution you need to us , system ("/bin/ls"); Below is the update ******************************************************* Also , you can use the below program to list the directories,