C Shell in linux.. only recognizes echo command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting C Shell in linux.. only recognizes echo command
# 1  
Old 10-05-2010
C Shell in linux.. only recognizes echo command

Hi guys,
So my code is below. This is a simplified version of the shell... It does not continue for ever... I guess its actually rather a program to accept a command.. has the fork and the execve etc. Anyways when i compile it and run it in the terminal for some reason only '/bin/echo "enter text here"' works...
But when i try to use a command like /bin/ls "directory" it wont work.. but when i call /bin/ls "directory" in the terminal (not in my half-shell) it works perfectly fine.. So i dont know if this could be a problem with my code.
Thanks
Guys

Code:
#include <string.h>
#include <errno.h>
#include <stdio.h>

#define TRUE 1


int main()
{
int n = 0;
int status;
char *argv[100];
char temp[256];

fgets(temp, sizeof(temp), stdin);
argv[n++] = strtok (temp," ");

while (argv[n-1] != NULL)
argv[n++] = strtok (NULL, " ");

// This is merely to print out what got splitted for the tokens////////////////////////////
int b=0;
while (argv[b] != NULL)
{
printf ("%s\n", argv[b]);

b++;
}
//////////////////////////////////////////////////////////////////////////////

if (fork() != 0)
    {
    waitpid(-1, &status, 0);
    }
else
    {
        if (execve(argv[0], argv, 0) == -1) /* execute command */
        printf(": %s\n", strerror(errno));
    }
    

}

# 2  
Old 10-05-2010
Maybe it needs the environment. You are using execve but a null environment pointer. I use execvp for same env and path as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux shell | how to exit a script if any command fails.

Hi, i am new here let me say HI for all. now i have a question please: i am sending one command to my machine to create 3 names. if one of the names exists then the box return error message that already have the name but will continue to create the rests. How i can break the command and... (7 Replies)
Discussion started by: Amiri
7 Replies

2. Shell Programming and Scripting

Need to echo command successful if command is executed successfully

Hello, I have written a command n shell script : srvctl relocate service -d t1 -s s1 -i i1 -t t1 -f If the above command executes successfully without error I need to echo "Service relocated successfully and If it errors out I need to trap the errors in a file and also need to make... (1 Reply)
Discussion started by: Vishal_dba
1 Replies

3. Shell Programming and Scripting

How to echo output of a UNIX command (like ls -l ) using shell script.?

How do i echo the output of a unix command using shell script??? Like: echo /etc/ ls -l (2 Replies)
Discussion started by: sunny2802
2 Replies

4. UNIX for Dummies Questions & Answers

Confusion with echo command under csh shell

HI, guys, I am having some problem with the echo command, so I want to echo some text to a file name loginFile, the result inside the loginFile should looks like: expect ">" so what I did is: echo "expect "">""" >> $loginFile but it just gave out: expect > The thing is I still need... (2 Replies)
Discussion started by: warmboy610
2 Replies

5. Shell Programming and Scripting

rm:command not found in linux Bash shell script

Hi All, Linux lxs3er06 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 i686 i386 GNU/Linux Issue: While executing shell scripts in bash shell, following error messages are thrown: rm:command not found On doing little investigation, I added '/bin' to $PATH and on doing echo... (9 Replies)
Discussion started by: a1_win
9 Replies

6. Homework & Coursework Questions

Can anyone help? I have to Write a program in C that recognizes the following commands and translate

I have to Write a program in C that recognizes the following commands and translates them into much simpler ones Commands to recognize shorter command list L cd dir C - dir_length - dir get file_name G - file_name_length - file_name Long commands are read from the standard input... (1 Reply)
Discussion started by: aintour
1 Replies

7. UNIX for Dummies Questions & Answers

Can anyone help? I have to Write a program in C that recognizes the following commands and translate

I have to Write a program in C that recognizes the following commands and translates them into much simpler ones Commands to recognize shorter command list L cd dir C - dir_length - dir get file_name G - file_name_length - file_name Long commands are read from the standard input and... (1 Reply)
Discussion started by: aintour
1 Replies

8. Solaris

Confused with echo $SHELL Command....

Hi.. Everyone... Kindly consider following : login as: root Using keyboard-interactive authentication. Password: Last login: Mon Nov 3 19:30:50 2008 from xxxxxxxxxxx Sun Microsystems Inc. SunOS 5.10 Generic January 2005 You have new mail. Sourcing //.profile-EIS..... # # ... (3 Replies)
Discussion started by: Reboot
3 Replies

9. Linux

Basic Linux Shell Command

I'm working with telnet under windows and Xming. I connect to a network computer and I open Xterm. With Xterm I want to be able to open more than one windows like firefox, nedit etc. Example : When a open firefox on the xterm, I type "firefox", after that, I cannot make an other command until I... (1 Reply)
Discussion started by: Meccos
1 Replies
Login or Register to Ask a Question