zebra barcode printer vb net 9: Using the Linux Shell in Software

Drawer Code 128 Code Set B in Software 9: Using the Linux Shell

9: Using the Linux Shell
Make Code 128 Code Set B In None
Using Barcode creator for Software Control to generate, create Code 128C image in Software applications.
Recognizing Code-128 In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
FIGURE 9-45
Code-128 Printer In Visual C#
Using Barcode creator for .NET Control to generate, create Code-128 image in Visual Studio .NET applications.
Code 128A Creator In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create Code 128 Code Set B image in ASP.NET applications.
Putting scripts in ~/bin
Draw Code 128B In VS .NET
Using Barcode encoder for VS .NET Control to generate, create Code 128 Code Set C image in .NET framework applications.
Code 128 Code Set C Maker In VB.NET
Using Barcode generator for VS .NET Control to generate, create Code 128B image in VS .NET applications.
Because it s in the PATH, any files you put in ~/bin can be run from the shell prompt without specifying the full path to the file You could also, of course, create your own directory and manually edit your bash configuration files to add it to your user s PATH environment variable as well With this background in mind, let s spend some time discussing how to create a basic shell script
Data Matrix 2d Barcode Drawer In None
Using Barcode encoder for Software Control to generate, create Data Matrix 2d barcode image in Software applications.
Encoding Code 39 Full ASCII In None
Using Barcode generation for Software Control to generate, create ANSI/AIM Code 39 image in Software applications.
Creating a Basic Script
Painting GTIN - 128 In None
Using Barcode encoder for Software Control to generate, create UCC.EAN - 128 image in Software applications.
UCC - 12 Encoder In None
Using Barcode encoder for Software Control to generate, create UPC A image in Software applications.
As we mentioned earlier, shell scripts can be extremely basic or extremely complex The example we reviewed earlier was a very simple script It echoed text on the screen and ran one command For your Linux+ exam, you need to be able to create scripts that are more complex than this one Therefore, in this part of the chapter, we re going to cover the following topics:
Barcode Printer In None
Using Barcode creator for Software Control to generate, create barcode image in Software applications.
Code 128 Generation In None
Using Barcode creation for Software Control to generate, create Code-128 image in Software applications.
Displaying text on the screen Adding commands to a script Reading input from the user
OneCode Creator In None
Using Barcode maker for Software Control to generate, create Intelligent Mail image in Software applications.
Painting Code 128A In Java
Using Barcode encoder for Android Control to generate, create Code 128A image in Android applications.
Let s begin by discussing how to display text on the screen in a shell script
Make Code 128C In Objective-C
Using Barcode drawer for iPad Control to generate, create Code 128C image in iPad applications.
USS Code 39 Scanner In .NET
Using Barcode reader for .NET Control to read, scan read, scan image in .NET applications.
Create Shell Scripts
Data Matrix 2d Barcode Maker In Objective-C
Using Barcode maker for iPad Control to generate, create Data Matrix 2d barcode image in iPad applications.
Code 128 Code Set C Drawer In None
Using Barcode drawer for Online Control to generate, create USS Code 128 image in Online applications.
Displaying Text on the Screen
Drawing Barcode In Visual Studio .NET
Using Barcode drawer for Reporting Service Control to generate, create barcode image in Reporting Service applications.
Paint GS1 - 13 In None
Using Barcode creator for Font Control to generate, create European Article Number 13 image in Font applications.
This task is pretty easy As you saw in the earlier examples we reviewed, you can display text on the screen in a shell script using the echo command The syntax for using echo is to simply enter echo text_to_be_displayed in the script file For example, in Figure 9-42, we entered echo The current date and time is: to display the associated text on the screen Because the shell script simply calls and runs the echo command, you can use all of the options you would use if you were to run echo at the shell prompt Check out the man page for echo to see what s available In addition to displaying text on the screen, you can also run commands from the script Let s review how this is done next
Adding Commands to a Script
To run a shell command from within a script, simply enter the appropriate command in the script with all of the options you want to include with it In Figure 9-42, we used the date command to display the current date and time You can include just about any command you want in your shell scripts Just remember to put each command on a separate line unless you are using pipes to move data between commands Let s make things a little more interesting by discussing how to gather input from the user in a script
Reading Input from the User
Up to this point, our scripts have been very simple and non-interactive, meaning that the user simply types the command at the shell prompt and the script does whatever it s been written to do However, you can make your scripts more flexible by making them interactive, meaning that you can have your scripts ask the user a question and then capture their input for processing This is done using the echo command discussed previously in conjunction with the read variable command The echo command is used to present the user with a question The read variable command is used to pause the script, present a prompt on the screen, and read the information the user supplies into a variable you define Consider the example shown in Figure 9-46 In this script, the user is prompted for the name of the directory he or she wants to add to the PATH environment variable The read command provides the user with a prompt to enter the directory name When the user presses the key, the value he or she typed is assigned to the variable named MYNEWPATH
retne
9: Using the Linux Shell
FIGURE 9-46
Querying the user for input in a shell script
Once the variable was stored in memory, the echo command was used a second time to display the value of MYNEWPATH on the screen Now, we didn t actually modify the PATH variable yet To do this, we need to add some more commands to the shell script The best way to approach this is to ask yourself: If I were doing this from the shell prompt, what commands would I need Then enter the commands in the script and try it out In this example, we need to add the directory specified by the user to PATH and then export PATH This could be done using the command shown in Figure 9-47 If you ve done any programming, you probably noticed that we didn t have to declare the MYNEWPATH variable anywhere in the script With many scripting and programming languages, you have to first declare a variable, set its size, and specify what type of information (text string, real number, integer, Boolean value,
FIGURE 9-47
Copyright © OnBarcode.com . All rights reserved.