Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
Like Tree1Likes
I am new to linux, I have an assignment for my operating system class, I don't know where to start. The question is Create a Linux shell (in other words, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4

    Linux programmin help


    I am new to linux, I have an assignment for my operating system class, I don't know where to start. The question is

    Create a Linux shell (in other words, write a C program) that will recursively prompt for input from the user. The shell should prompt as
    yourRollNumber-currentDirectoryName>

    For instance if the current directory is /home/OS and your roll number is 1234567, the shell should prompt as:
    1234567-OS>


    any help in this regard will be highly appreciated. Let me know where to start Please..............

  2. #2
    Linux Newbie
    Join Date
    Apr 2012
    Posts
    112
    Quote Originally Posted by ooommii View Post
    I am new to linux, I have an assignment for my operating system class, I don't know where to start. The question is

    Create a Linux shell (in other words, write a C program) that will recursively prompt for input from the user. The shell should prompt as
    yourRollNumber-currentDirectoryName>

    For instance if the current directory is /home/OS and your roll number is 1234567, the shell should prompt as:
    1234567-OS>


    any help in this regard will be highly appreciated. Let me know where to start Please..............
    Have a look at this link, it might help

  3. #3
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4
    [

    well thanks, I am not looking for how to change the outlook. I am looking for procedures running background using command ls, pwd etc. I have to write a program in c, that prompt for user input and show your working directory, thanks

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    May 2012
    Posts
    43
    Still not entirely sure what your question is, but here's how to get the current working dir.

    Code:
    ${PWD##*/}
    Not sure what yourRollNumber is meant to be or how it's meant to be obtained.

  6. #5
    Administrator jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    5,023
    Hello and Welcome!

    I'm not exactly a pro at writing scripts. But maybe if you post what you have started with, others may be able to chime in with some pointers for you.
    Other than that, the best that we may be able to provide is a few links to sites similar to the one posted above.
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to private messages asking for Linux help. Please keep it on the public boards.

  7. #6
    Linux Newbie
    Join Date
    Apr 2012
    Posts
    112
    Quote Originally Posted by ooommii View Post
    [

    well thanks, I am not looking for how to change the outlook. I am looking for procedures running background using command ls, pwd etc. I have to write a program in c, that prompt for user input and show your working directory, thanks
    There is a function called getcwd that will do what you want, i.e. get the current working directory.

    Is the roll number the user name in the system?

    If it is you could try this:

    printf("%s@shell:%s$", getenv("USER"),getenv("PWD"))

    from here

    or use the getuid function.

    Edit.

    As an aside you learn a lot more from trying that from somebody giving you the answer.

    I vaguely remembered the getcwd function from back in the day, so I had to do a bit of research [Googling to you and me] to confirm what it was called and during that search I stumbled upon the stackoverflow post.

    You have to ask yourself, what are you trying to do? Learn or pass your module/class

    I had the same attitude when I was at uni and it was the wrong attitude. I finished with a good Physics degree and hardly any knowledge. If you really want to learn, then you are going to have to put the time in.

    sorry about the rant [monday morning, I is Cranky ]
    Last edited by manyrootsofallevil; 10-15-2012 at 07:06 AM.

  8. #7
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4
    Thanks, everyone for your time, I am still no getting the answer. I looking for procedures or source code that run these commands. Anyways thanks..............

  9. #8
    Linux Newbie
    Join Date
    Apr 2012
    Posts
    112
    Quote Originally Posted by ooommii View Post
    Thanks, everyone for your time, I am still no getting the answer. I looking for procedures or source code that run these commands. Anyways thanks..............
    I think you'll find what you want here

  10. #9
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,637
    If you are completely stuck on how to start an assignment the best person to ask for help is your tutor. Not only will that help you with the assignment, it will help your tutor tailor the class material so it is more useful for you.

    It is against the rules here to do someone's homework for them so you are unlikely to get a complete solution. However, posting what you have done so far and asking a specific question about it will usually get you pointed in the right direction.
    "I used to be with it, then they changed what it was.
    Now what was it isn't it, and what is it is weird and scary to me.
    It'll happen to you too."

    Grandpa Simpson



    The Fifth Continent

  11. #10
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4
    thanks for your advice, i am not asking for homework, i am just asking about the source code for command like ls, pwd etc...
    ayways i got your point. tnx

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •