7 Replies - 621 Views - Last Post: 28 September 2015 - 06:26 AM Rate Topic: -----

#1 Bawnawgwa   User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 153
  • Joined: 21-January 13

Creating a shell with unique command line in C

Posted 25 September 2015 - 08:15 AM

So I am to create a shell in C on Linux. It will be ran by entering:

./shell -p "something> "

Then the command line will change from blahblah~:$ to something>

My problem is is it possible to change the command line like that where every time the user enters a new command argc and argv update? Or do I just have to print the command line in a loop and scan the input?

I feel just scanning the input can make dealing with switches difficult.

I found the command export PS1 = "whatever> " but that hasn't helped because it says export isn't a recognized command.

I would love some help! I've been trying to set this up for far too long with no success.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a shell with unique command line in C

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6292
  • View blog
  • Posts: 21,622
  • Joined: 05-May 12

Re: Creating a shell with unique command line in C

Posted 25 September 2015 - 10:44 AM

I suggest re-reading the requirement for your assignment. Do you know what a shell is? Do you realize that while the shell is running, it will keep prompting for more input until you exit it? For each command that the user enters while running your shell, it will not go back into through your main() entry point?
Was This Post Helpful? 0
  • +
  • -

#3 Bawnawgwa   User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 153
  • Joined: 21-January 13

Re: Creating a shell with unique command line in C

Posted 26 September 2015 - 06:51 AM

That is the assignment. So I need to just scan the input each time and interpret it on my own instead of using argc and argv?

It is supposed to work like a shell, written in C, that can execute a few basic commands from command line.
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3796
  • View blog
  • Posts: 13,742
  • Joined: 08-August 08

Re: Creating a shell with unique command line in C

Posted 26 September 2015 - 07:32 AM

That took me about 15 minutes to do in C++. Show what you've tried.
Was This Post Helpful? 0
  • +
  • -

#5 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: Creating a shell with unique command line in C

Posted 27 September 2015 - 09:21 PM

@CTphpwb 15 mins! I know you can do better than that :)
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3796
  • View blog
  • Posts: 13,742
  • Joined: 08-August 08

Re: Creating a shell with unique command line in C

Posted 28 September 2015 - 04:04 AM

:innocent:
But I had to come up with some sample commands! I finally decided on ls, time, exit, help, and command not found.
Was This Post Helpful? 0
  • +
  • -

#7 Xupicor   User is offline

  • Nasal Demon
  • member icon

Reputation: 457
  • View blog
  • Posts: 1,179
  • Joined: 31-May 11

Re: Creating a shell with unique command line in C

Posted 28 September 2015 - 06:22 AM

So that's 10, couldn't you squeeze in a scripting language? You still had 5 minutes left. : P
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3796
  • View blog
  • Posts: 13,742
  • Joined: 08-August 08

Re: Creating a shell with unique command line in C

Posted 28 September 2015 - 06:26 AM

I thought it would be best to stick to the spec. ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1