However, sometimes you have a set of commands that you have to repeat regularly, even at different times and in different shell sessions. The only slightly less easy way: the script Īs we saw in the last section, you can very easily execute shell commands for all purposes by starting an interactive shell session and typing your commands in at the prompt. If you're using such a shell, just type the word "exit" (like with any other command) and press Enter (from here on in, I'll leave the "Enter" out of examples). Some modern shells have disabled the use of Control+d in favor of the "exit" command (shame on them). This key combination produces the Unix end-of-file character - we'll talk more later about why this also terminates your shell session. To quit the shell session, hit Control+d. We'll get back to what this does exactly in a later chapter, but for now just remember this is the way to interrupt things. To interrupt a running program or shell command, hit the Control and C keys at the same time. The shell is used in this way very often, both to execute commands that belong to the Bourne Shell programming language and simply to start running other programs (like the ls program from the example above).īefore we move on, we'll mention two useful key combinations when using the shell: the command to interrupt running programs and shell commands and the command to quit the shell (although, why you would ever want to stop using the shell is beyond me.). This is the simplest way of executing shell commands: typing them in one at a time and waiting for each to complete in order. Give it a try: type the commandĪfter a short time, you'll see a list of files in the working directory (the directory that your shell considers the "current" directory), a new prompt and the cursor. At some point the operating system will be finished working on your command and the shell will bring up a new prompt and the cursor as well and will then start waiting again for you to enter another command. You'll notice that your cursor will disappear momentarily while the command is being carried out, and you cannot type anymore (at this point, the Bourne Shell program is no longer in control of your terminal - the other program that you started by executing your command is). The shell then translates your command to something the operating system understands and passes off control to the operating system so that it can actually carry out the task you have sent it. You execute commands in interactive mode by typing them in, followed by a press of the Enter key. Specifically, the program you accessed a moment ago is your shell, running in interactive mode: the shell is running in such a way that it displays a prompt and a cursor (the little, blinking line) and is waiting for you to enter a command for it to execute. That's your shell: your direct access to everything the system has to offer. The admin says: everybody, STOP TRYING TO CRASH THE SYSTEM You'll probably end up looking at a screen looking something like this: In your Unix environment, go to a terminal either a textual logon terminal, or a terminal-in-a-window if you're using the X Window System (look for something called xterm or rxvt or just terminal, if you have actually not ever done this yet). Surprise: you've been doing shell scripting for a while already! If you have access to a Unix-based machine (or an emulator on another operating system), you've probably been using the Bourne Shell - or one of its descendants - already, possibly without realising. The easy way: the interactive session Taking another look at what you've probably already seen 3.3 A useful thing to know: background processes.3.1 Why you want to know about multiprocessing.3 A little bit about Unix and multiprocessing.2.3 Running a shell script the other way.2 The only slightly less easy way: the script.1.2 Using the shell in interactive mode.1.1 Taking another look at what you've probably already seen.1 The easy way: the interactive session.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |