386 views
3 votes
3 votes
Unix is a command line-driven operating system. The Unix command line behaves in a similar manner to the MATLAB interpreter: users repeatedly enter commands at a prompt (denoted by the character >’). You are to write a "command line" that repeatedly prompts the user for a command and repeats it back to them. The user can exit the command line when only the character q is passed (meaning "quit"). For example:

>> command_line
> ls ../folder
You entered: ls ../folder
> echo hello world!
You entered: echo hello world!
> q

User Mar Mar
by
3.4k points

1 Answer

3 votes
3 votes

Answer:

function command_line()

while 1==1

x = input('>','s');

if x == 'q'

user_message = sprintf('Shutting down the program now... ');

disp(user_message)

Step-by-step explanation:

  • Create a function called command_line and run a while loop loop inside it.
  • Take input from user and keep on displaying it.
  • Check whether the user entered the letter q, then display the "Shutting down the program now..." message and then terminate program.
User MWid
by
3.5k points