0

Ok so I created my own shell, and I've tested it plenty on my own, but I need shell scripts that will run it and test it.

I've create a script which consist of this:

#!/bin/bash
echo "ls && echo dog" | ./a.out

However, all it does is print the command prompt "$" infinitely, and I have to force quit the program. therefore I am pretty sure my program does not like my script lol. My program works by using getline to capture the user input until they push <enter> and the boost library to tokenize the string and look for connector e.g "||" "&&" ";" and and so on, then run the commands. All of this is done in a while loop that loops until the user types exit and I close my program. Being as I am new to writing scripts I am sure I probably am not writing my script in the best of manners. I created a simple program to ask for your age and then output it and this script method works for that, but being as my shell isn't as simple I am not surprised this scrip doesn't seem to work.

string user_input;
bool good = true;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;

    while(good){
        //command prompt
        cout << "$ "; 

        //read in user input
        getline(cin, user_input);

        //tokenize user input
        tokenizer tok(user_input);
        //parse and execute commands inputed by user in string 
        //only exit while loop if user command is <exit> good = false    
    }

my shell works if I execute the program normally and I enter inputs into the program what I need is a shell script that I can use to run and test the program for me. Ex. if I type ./script.sh in the standard linux shell it will run my script which will then execute my a.out and then test my own shell with a variety of commands Examples being ls echo ...

1
  • It's not possible to analyze a problem and provide useful results with any reliability when you've given us zero code to analyze. Can you provide a Minimal, Complete, and Verifiable example? Commented Feb 3, 2016 at 4:03

1 Answer 1

1

You should exit the shell when you reach EOF (End Of File). Getline while return -1 in that case. I can't think of any other advice as you didn't provide any code, but this might resolve the infinite loop issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.