Best way of making a shell

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Best way of making a shell

Post by iansjack »

I assure you I didn't get my reward checks without doing it.
A notable achievement I'm sure, but let's use facts rather than achievements to back up arguments.

You certainly can implement a queue with a linked list (but that is not the only possible implementation - you could implement a queue using an array if you chose to). That doesn't mean that a linked list is equivalent to a queue. Those who use, for example, FIFO queues in their programs would probably not impressed by your pettifogging. If it pleases you then by all means please yourself.

Enough of this silly diversion I think.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Best way of making a shell

Post by dozniak »

Love4Boobies wrote:It's hardly entertaining if you didn't get the joke.
I did, I did, thanks.
Learn to read.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Best way of making a shell

Post by computertrick »

sortie wrote:The best way of making a shell is writing a lexer and a parser that generates an abstract syntax tree representing the commands that user want executed. This is trivial for a shell that only understands 'foo bar baz' commands, but things get more complicated if you add environmental variables, escape characters, quotes, pipes, conditionals, and all the other good shell features. Depending on your shell language, another approach may be better, but lexer+parser is a good and well-understood solution for parsing context-free programming languages.

Why use a stack as a stack? Just allocate 256 characters as a string and fill it up from the start using user-input. When it fills up completely, you reallocate and double its size and then continue. When you encounter a newline, you discard that character, put in a '\0' that terminates the string and call execute_a_shell_command(const char*). Voila!
My operating system is written entirely in assembly so the best approach would be doing something like this ?

Code: Select all

STRING db 0x00
And then using SI register to act as a pointer?
1100110100010011
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Best way of making a shell

Post by sortie »

I suggest you learn your programming language (in this case assembler). Once you know it, it should be easy to do what you are asking.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Best way of making a shell

Post by Love4Boobies »

iansjack wrote:You certainly can implement a queue with a linked list (but that is not the only possible implementation - you could implement a queue using an array if you chose to). That doesn't mean that a linked list is equivalent to a queue. Those who use, for example, FIFO queues in their programs would probably not impressed by your pettifogging. If it pleases you then by all means please yourself.
You missed the point. I never claimed linked lists were the only possible implementation (I even used the word "usually" to suggest the contrary). A data structure is a pattern of data organization---it is already an implementation. ADT's are defined by their semantics.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Best way of making a shell

Post by computertrick »

This is the final way i came up with

Code: Select all

	BITS 16
	ORG 0

start:
	cli
	mov ax, cs
	mov ds, ax
	mov es, ax
	sti

setup_str:
	mov si, STRING	; Clean up STRING 
	mov cl, 20	; 20 bytes 
	call clean
keypress:

	mov ah, 00h	; Check for key press
	int 16h
	cmp al, 13	; Enter pressed?
	je execute	; Then execute command
	mov ah, 0eh
	int 10h
	mov byte [si], al
	lodsb
	jmp keypress
execute:
	mov si, STRING	; Print out string
	call print	
	jmp setup_str	; Reset String

print:
	pusha
	mov ah, 0eh
.repeat:
	lodsb
	cmp al, 0
	je .done
	int 10h
	jmp .repeat
.done:
	popa
	ret

clean:
	pusha
.repeat:	
	cmp cl, 0
	je .done
	mov byte [si], 0
	dec cl
	lodsb
	jmp .repeat
.done:
	mov si, STRING
	popa
	ret
	
; Variables

STRING times 20 db 0 ; Allocate 20 bytes for input string
CHAR_COUNT DB 0
How did i do? can anyone think of a better way

also the shell isn't complete this is just my example of how I am storing the users commands
1100110100010011
Locked