25.03.2013 Views

Copyright Sams Teach Yourself Shell Programming in 24 Hours

Copyright Sams Teach Yourself Shell Programming in 24 Hours

Copyright Sams Teach Yourself Shell Programming in 24 Hours

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Interactive mode means that the shell expects to read <strong>in</strong>put from you and execute the commands<br />

that you specify. This mode is called <strong>in</strong>teractive because the shell is <strong>in</strong>teract<strong>in</strong>g with a user. This is usually<br />

the mode of the shell that most users are familiar with: you log <strong>in</strong>, execute some commands, and log out.<br />

When you log out us<strong>in</strong>g the exit command, the shell exits.<br />

The shell can be run <strong>in</strong> another mode, called non<strong>in</strong>teractive mode . In this mode, the shell does<br />

not <strong>in</strong>teract with you; <strong>in</strong>stead it reads commands stored <strong>in</strong> a file and executes them. When it reaches the<br />

end of the file, the shell exits.<br />

How log<strong>in</strong> Starts a <strong>Shell</strong><br />

When the log<strong>in</strong> program starts a shell, it basically executes the follow<strong>in</strong>g command:<br />

/b<strong>in</strong>/sh<br />

By issu<strong>in</strong>g this command, it puts the shell <strong>in</strong>to <strong>in</strong>teractive mode. You can start a shell <strong>in</strong> <strong>in</strong>teractive mode by<br />

issu<strong>in</strong>g the same command at the prompt:<br />

$ /b<strong>in</strong>/sh<br />

$<br />

The first prompt $ is displayed by the shell that log<strong>in</strong> started; the second one is displayed by the shell you<br />

started. To exit from this shell, use the exit command:<br />

$ exit<br />

$<br />

The prompt that is displayed now is from the orig<strong>in</strong>al shell started by log<strong>in</strong>. Typ<strong>in</strong>g exit at this prompt<br />

logs you out.<br />

How to Start the <strong>Shell</strong> Non<strong>in</strong>teractively<br />

You can start the shell non<strong>in</strong>teractively as follows:<br />

$ /b<strong>in</strong>/sh filename<br />

Here filename is the name of a file that conta<strong>in</strong>s commands to execute. As an example, consider the<br />

compound command:<br />

$ date ; who<br />

Put these commands <strong>in</strong>to a file called log<strong>in</strong>s. First open a file called log<strong>in</strong>s <strong>in</strong> an editor and type the<br />

command shown previously. Assum<strong>in</strong>g that the file is located <strong>in</strong> the current directory, after the file is saved,<br />

the command can run as<br />

$ /b<strong>in</strong>/sh log<strong>in</strong>s

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!