The filename is used as an argument to (Web hosts)

The filename is used as an argument to the shell (e.g., bash script_file). In this method, the file does not need to be executable; it just contains a list of shell commands. The shell specified on the command line is used to interpret the commands in the script file. This is most common for quick, simple tasks. The shell script is executed by specifying the name of the file on the command line. This requires that the first line of the shell script contain the name of the shell interpreter that is to be used (e.g., #!/bin/bash as the first line of the file) and that the execute bit is set. This method is most common for complex scripts that may be used frequently. The first line of a shell script is the only line where the pound sign (#) isn’t interpreted as a comment. Cross-Reference See Chapter 3 for information on chmod and read/write/execute file permissions. The examples in this chapter are of the second variety. When scripts are executed in either manner, options to the program may be specified on the command line. Anything following the name of the script is referred to as a command-line argument. These are referenced within the script as the variables $1, $2, $3, . . . $n. The name of the script itself is held within the variable $0. Note that these are positional parameters, meaning that they refer to a position of information on the command line. While it is recommended that you choose meaningful variable names, there s still no substitute for active commenting throughout the design of the shell script. The pound sign (#) prefaces comments and can take up an entire line or exist on the same line as script code. When you are writing more complex shell scripts, it is best to implement them in stages, making sure the logic is sound at each step before continuing. One way to make sure things are working as expected during testing is to place an echo statement at the beginning of lines within the body of a loop. That way, rather than executing the code, you can see what will be executed without making any permanent changes. Another way to accomplish the same goal is to place dummy echo statements at various places throughout the code. If these lines get printed, you know the correct logic branch is being taken. With the bash shell, you could also use set +x near the beginning of the script to display each command that is executed. Besides commands, shell scripts can contain such components as user-defined variables, program constructs (such as loops and conditionals), and arithmetic instructions. These topics are described in the following sections. Creating user-defined variables in shell scripts Often within a shell script, you want to reuse certain items of information. During the course of processing the shell script, the name or number representing this information may change. To store information used by a shell script in a way that it can be easily reused, you can set variables. Variable names within shell scripts are case-sensitive and can be defined in the following manner: NAME=value The first part of a variable is the variable name, and the second part is the value set for that name. For example, you can define a variable containing the city in which you live as follows: City=”Springfield” Technically, quoting is only necessary to preserve spacing within values, but it may aid in readability. Double quotes (”) are considered weak quotes, while single quotes (’) are considered strong quotes. Any special characters contained in a string surrounded by single quotes (for example, ’string’) are disabled. With double quotes, however, all special characters are disabled except dollar sign ($), single quote (’), and backslash ().
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Leave a Reply