run bash | set variables
If it ever becomes necessary to pass one of the special
Characters as a parameter to another program, one of three
Actions is required:
-prefix the character with a \ (for example, \$)
-surround the character with a pair of " (for example "#")
Note, this doesn't work for all characters
- surround the character with a pair of ' characters (for example '$')
This works for all characters except '
echo "the fee is $10" --> the fee is 0
echo 'the fee is $10' --> the fee is $10
echo the fee is \$10 --> the fee is $10
echo the fee is "$"10 --> the fee is $10
echo the fee is "$10" --> the fee is 0
There are 4 ways to run a shell script on the command-line
1.myscript
The script must be executable
2.sh myscript
Technically the same as method 1., but the file doesn't need
To be made executable
3. .myscript
The commands in the script are executed by the CURRENT shell
4.exec myscript
The current shell terminates, spawning a new shell in its place
To execute the script.
As soon as the script has terminated, the user is logged off
Running s script from within VI
---
While using vi, typing :! Allows you ot run any single
UNIX command (including the scipt being edited)
:! ls
This exact command can be repeated at any time by typing:
: !!
---
A further shortcut offered by vi is that the name of the
file currently being edited can be inserted into the
command-line by typing the % character
Your PATH and bin
Your PATH is a shell variable containing a list of
Directories that the shell should look in to locate
Executable files (separated by ":"). It is typically set in your .profile
----
The Bourne shell is not the only program that can be
used to run scripts.
Others include:
- The C shell (csh)
- sed
- awk
- perl
- tcl
- And many others
When you type in the name of a script on the command-line,
The following actions are taken by your shell:
1. The file is located and opened
2. The first few charactes are examined to determine what type of
Executable it is (binary or script)
3. If it is a script (and no interpreter is scpecified), the shell
Attempts to interpret and run the script
It may be that your login shell is the C shell , and the script
You are tryinh to run was written for the Bourne shell (or vice-versa)
It is also possible the script could be a perl script
To enable the shell to know what program should be run to interpret
The script, the script interpreter may be specified on the first line of the
Script, in the following manner:
#! /bin/sh
or
#! /bin/csh
or
#! /usr/local/bin/perl
This is absolutely essential for CGI programming
-------
- A CGI program is a program that is used to provide
Interactivity, automation or database connectivity to
A web site
- A CGI program can be any type of program, including
Bourne shell scripts
- For a Bourne shell script to act as a CGI script, it must
Have the followingattributes:
==It must be executable
==It must begin with the line #!/bin/sh
==Any output produced must be recognised as a valid HTTP
stream. This requires that Standard Output begin with a line
such as the following:
Content-type: text/html
Variables must not begin with a digit
All shell variables are STRINGS
If you need to assign a value that contrains spaces to
A variable, use the " character.
Street="Smith Avenue"
Characters as a parameter to another program, one of three
Actions is required:
-prefix the character with a \ (for example, \$)
-surround the character with a pair of " (for example "#")
Note, this doesn't work for all characters
- surround the character with a pair of ' characters (for example '$')
This works for all characters except '
echo "the fee is $10" --> the fee is 0
echo 'the fee is $10' --> the fee is $10
echo the fee is \$10 --> the fee is $10
echo the fee is "$"10 --> the fee is $10
echo the fee is "$10" --> the fee is 0
There are 4 ways to run a shell script on the command-line
1.myscript
The script must be executable
2.sh myscript
Technically the same as method 1., but the file doesn't need
To be made executable
3. .myscript
The commands in the script are executed by the CURRENT shell
4.exec myscript
The current shell terminates, spawning a new shell in its place
To execute the script.
As soon as the script has terminated, the user is logged off
Running s script from within VI
---
While using vi, typing :! Allows you ot run any single
UNIX command (including the scipt being edited)
:! ls
This exact command can be repeated at any time by typing:
: !!
---
A further shortcut offered by vi is that the name of the
file currently being edited can be inserted into the
command-line by typing the % character
Your PATH and bin
Your PATH is a shell variable containing a list of
Directories that the shell should look in to locate
Executable files (separated by ":"). It is typically set in your .profile
----
The Bourne shell is not the only program that can be
used to run scripts.
Others include:
- The C shell (csh)
- sed
- awk
- perl
- tcl
- And many others
When you type in the name of a script on the command-line,
The following actions are taken by your shell:
1. The file is located and opened
2. The first few charactes are examined to determine what type of
Executable it is (binary or script)
3. If it is a script (and no interpreter is scpecified), the shell
Attempts to interpret and run the script
It may be that your login shell is the C shell , and the script
You are tryinh to run was written for the Bourne shell (or vice-versa)
It is also possible the script could be a perl script
To enable the shell to know what program should be run to interpret
The script, the script interpreter may be specified on the first line of the
Script, in the following manner:
#! /bin/sh
or
#! /bin/csh
or
#! /usr/local/bin/perl
This is absolutely essential for CGI programming
-------
- A CGI program is a program that is used to provide
Interactivity, automation or database connectivity to
A web site
- A CGI program can be any type of program, including
Bourne shell scripts
- For a Bourne shell script to act as a CGI script, it must
Have the followingattributes:
==It must be executable
==It must begin with the line #!/bin/sh
==Any output produced must be recognised as a valid HTTP
stream. This requires that Standard Output begin with a line
such as the following:
Content-type: text/html
Variables must not begin with a digit
All shell variables are STRINGS
If you need to assign a value that contrains spaces to
A variable, use the " character.
Street="Smith Avenue"
Comments
Post a Comment