Quote:
Originally Posted by Adol
Not sure what my syntax error is.
|
As the link posted by
ondoho demonstrates, the syntax of an
if command is:
Code:
if CONDITION
then
STATEMENTS
fi
Note that
“then” is on a separate line, i.e., it is a statement in its own right.
Alternatively, you could insert a semicolon (i.e.,
“;”) between the CONDITION and the
“then”:
Code:
if CONDITION ; then
STATEMENTS
fi
Quote:
I can change the #!/bin/sh to #!/bin/bash
Does this actually make a difference in the script? I thought that since I used the hashtag it doesn't read that line.
|
If the first line of a script starts with a
“hashbang” (i.e.,
“#!”—a
hash followed by a
bang or exclamation mark), then it will be called the
“hashbang” or
“shebang” line, and it will be considered special, in that it should then identify the program that will be used to run the script.
Thus, if your script begins with
“#!/bin/sh”, then it will be run by the
/bin/sh program—i.e., the default command shell on your system. If, on the other hand, it begins with
“#!/bin/bash”, then it will be run specifically by the bash shell. Using the default shell should be the more portable option, while bash will generally be more powerful—but if you use any features that only bash supports, then your script will not run on a system on which bash is unavailable.
In fact, the
“shebang” line can be set to other values as well, such as
“#!/usr/bin/perl” (for a Perl script), or
“#!/usr/bin/python” (for a Python script), or even
“#!/usr/bin/python3” (for a Python script that requires Python 3, and will not work with Python 2).