Java or C for creating a unix shell?

Hi,

Great to find this forum!
I'm a complete newbie to unix, and am having a hard time finding my way around.
Firstly, I've been reading something about c shell programming being one tenth the size of c programming done on unix.....I couldn't figure what that meant, but there were two different kind of syntaxes shown.
Searching on the net also showed that Java could be used for creating a unix shell. Is that true? I mean, if I want to create a shell of my own, will Java be powerful enough to start and stop processes or create new processes etc?

Thanks.

For performance reasons you'd be ill advised to implement a shell in Java, in my opinion. However, if portability is very important for you, there may be an argument to do so. I see no technical reason that would prevent you from doing so.

C shell programming (or scripting) and C programming are very different things, I'm not sure why you'd even compare them like that? C is a compiled language that generates fast, efficient binaries. C shell is a command/script interpreter, and not a choice of shell that I would personally recommend.

Thanks Annihilannic!
Performance is important to me. I guess C would be better then.

ok, so shell scripting is done in C? I was under the impression that it was with using those echo commands etc like using batch files in MSDOS.

The point is, that when I was working on an old 286 computer (long time ago) which had only MSDOS, I had created a QBASIC program which pretty much acted like a GUI for MSDOS. It used batch files to execute DOS commands, while BASIC provided a user friendly interface.
I was quite happy to know that a UNIX shell can also be created with C, but knowing nothing about it, I didn't know where to start.

Could you give me some pointers as to where to refer for info on this? Do I just write a C program to imitate a unix shell and if I call it shell.exe, and run it from the unix prompt, will it actually behave like a real unix shell? Will I be able to control processes from this shell I create?

Err... no. Shell scripting is done in the language of whatever command shell you choose to use, whether it happens to be MS-DOS (COMMAND.COM), C shell (/usr/bin/csh), Korn shell (/usr/bin/ksh), bash, zsh, sh, .... the list goes on. Shell scripting is a generic term.

C shell just happens to be a shell that uses some constructs that are similar to the C programming language, which may be convenient for a C programmer, however (as you have demonstrated) it causes some confusion, and doesn't necessarily result in the most well defined scripting language.

The shells themselves are for the most part compiled C binaries. I really don't think you would be adding much value by writing yet another shell, unless of course it is purely for your own educational purposes. The common Unix shells are generally powerful enough to allow you to customise them by using scripting.

Yeah, it's just for learning how these shells work. Been a windows user for long...heard unix gives more power to the programmer. Thanks! :slight_smile:

I had the idea that I'd have to keep taking command line arguments from the user, just like the command prompt of bash keeps accepting commands.
But in order to take command line inputs, I'd have to repeatedly send values to main() right?
Is it possible/wise to do that or do I just create a while loop which keeps accepting strings?

It's not wise to do that, main() should only be called once. Just create a while loop.

Thanks :slight_smile: I had tried the while loop already....works great :slight_smile: