Help w/ writing a custom Linux shell using x86 assembly (NASM)


 
Thread Tools Search this Thread
Top Forums Programming Help w/ writing a custom Linux shell using x86 assembly (NASM)
# 1  
Old 09-18-2017
Help w/ writing a custom Linux shell using x86 assembly (NASM)

Hello world,

I thought this might be a great start to help me with an assignment I have that requires me to write an assembly program that mimics a 32 bit Linux command shell:


When launched, your program will perform the following steps in a loop:


1. Print a prompt, specifically “$ “ to the standard output file

2. Read a single line of input from the standard input file. A line is considered to end when a line feed character (‘\n') is encountered.

3. If the input line is “exit\n” your program must terminate

4. Otherwise, the user's input is to be treated as a command to be executed along with any arguments to be passed to that command.

5. Your program must launch the program specified by the user and pass any provided arguments along to the newly launched program. The program that you launch must, with the exceptions specified below, inherit its environment and standard file handles from your shell program. A single space shall be used to separate individual arguments on the user's supplied command line.

6. If the specified program fails to launch you must print the message: <prog>: command not found before returning to step 1 above. Here the user's desired program name is to be substituted for <prog>. For example
$ foofoo foofoo: command not found
$

7. Otherwise, your shell program must then wait for the program that you launch to complete before it prints its next prompt.

8. Upon completion of the program that was launched, return to step 1.

9. Properly recognize and handle output redirection specified by the user using the “>” (greater than) symbol in a provided command line. Everything to the left of the > is considered the command to execute along with its argument list. The one and only thing to the right of the > is the name of the file to which all of the command's standard output should be saved. The output file must be created with the permissions mask 0644 (that's octal by the way). If your shell cannot successfully open the named output file, you should print an error message (“<file>: Permission denied”) and refuse to execve the named command. For example:
$ /bin/ls -l > /etc/passwd
/etc/passwd: Permission denied
$

10. Properly recognize and handle piping specified by the user using the “|” (vertical bar) symbol in a provided command line. Everything to the left of the | is considered to be the producer command to execute along with its argument list. Everything to the right of the | is considered to be the consumer command to execute along with its argument list. The standard output of the producer process must be connected to the standard input of the consumer process. Your program must wait for BOTH processes to complete before returning to step 1 and printing a prompt.



----

I understand that I will need to use the 'execve' instruction, fork the parent process (shell), and dup2 for redirection.

I'm kinda lost as to where to start. Conceptually I am having a hard time figuring out just how a shell is created out of another shell (if I am even thinking about that the right way).

How should I start this program off, let's say forking the parent shell?
# 2  
Old 09-18-2017
We have a homework forum, that has additional requirements for posting. Please cut and post your question into that forum using the template
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to create custom options of my own in systemctl Linux?

Hello All, Greetings!! I was trying to create a custom option in systemctl like its out of the box options eg--> status, stop, start, restart, I have tried searching in google but didn't find anything related to it. Basically I would like to create a custom option which is related to... (9 Replies)
Discussion started by: RavinderSingh13
9 Replies

2. Programming

Custom icons for shell script

Hi, I have an application that I wrote in C using the GTK toolkit that runs on the Linux system. I have a shell script than when run executes two terminals to open a client and server application. I would like to know more on how to create custom start-up icons for my program. ie. using... (1 Reply)
Discussion started by: fedora18
1 Replies

3. Shell Programming and Scripting

Ps and top in a custom shell

I am having a hard time wrapping my head around implementing top and ps in a custom shell. What I have is a shell that allows you to do basic commands as you would in a regular bash shell, but when I do the ps command, it gives me all of the processes within my regular bash shell rather than my... (2 Replies)
Discussion started by: Ziun
2 Replies

4. Shell Programming and Scripting

Custom Shell

I have a jump off server, which grants SSH access to a few other servers. I would like to create a custom shell which can be assigned to specific user accounts which runs a menu script upon login, where they can select which server they want to jump too, however should they hit ctrl-c or any... (1 Reply)
Discussion started by: JayC89
1 Replies

5. UNIX for Advanced & Expert Users

Help creating a custom linux distro

Hi all, for a while now I've been working on a linux distro and I'm a couple of tweaks away from it to be perfected so if any experts want to help me out please message me. Thanks in advance. (I know I've posted a similar thread on the same topic but it was closed due to an unhelpful title... (0 Replies)
Discussion started by: allk
0 Replies

6. UNIX for Dummies Questions & Answers

Linux on custom hardware

I would like to configure a bare minimum Linux with internet browser on a system with Flash & RAM (but no harddisk or any other nonvolatile storage). Please advise. (5 Replies)
Discussion started by: rherb
5 Replies

7. UNIX for Advanced & Expert Users

Writing Custom Builtins for KSH93

I am looking to create some ksh93 extensions using the custom builtin feature. I can successfully create a builtin function, load it using the builtin -f command and get an output. However, I want to get/set values of KSH variables from within my built-in. For example, lets say I am creating... (2 Replies)
Discussion started by: a_programmer
2 Replies

8. Red Hat

Custom HA agent - Red Hat Linux Cluster

Hi experts, I have some custom application which I need to make Highly Available using red hat cluster service. How do I do it? i know in /usr/share/cluster i shall find HA agents for well known services like Apache or Sybase but I want to write HA agent for my own. I tried looking up on... (4 Replies)
Discussion started by: pshaikh
4 Replies

9. Solaris

custom jumpstart on x86 with DHCP/PXE goes into interactive mode

client boots fine, it gets the ip 192.168.0.10 and the bootfile. Then there is : SunOS 5.10 Version Generic_141445-09 32-bit" ... Configuring devices. Custom JumpStart Reading ZFS config: done Setting up Java. Please wait ... NOTE: Not enough memory for graphical installation. Graphical... (4 Replies)
Discussion started by: TomSu
4 Replies
Login or Register to Ask a Question