Hi.
Suppose you have a file like this:
Code:
# @(#) s4 Demonstrate command file, omitting shebang line.
echo " Hello, world."
In a script file, lines that begin with a "#" are comments. Empty lines can be added for readability.
In this example, the command
echo is basically a print statement. The text string on the line will be sent to the terminal output device.
There are a number of ways to get commands in a file executed. You can try the illustrations below for yourself. (I did a lot of copying and pasting, but I think the actions and the responses are in the correct order.)
The permissions on a file can be important. The permissions of this file can be seen with a command like:
which produces this cryptic output:
Code:
-rw-r--r-- 1 makyo makyo 82 Apr 21 17:27 s4
which, you will learn, means that you have
read and
write permission for this file, denoted by the first "rw" on the line.
As to how you can execute the commands in this file, you could try (case 1):
which produces:
Code:
bash: ./s4: Permission denied
you could also try (case 2):
producing:
and you could also do (case 3):
giving you:
Making the file executable for yourself with:
Code:
chmod +x s4
ls -l s4
producing (note the addition of "x", for
executable):
Code:
-rwxr-xr-x 1 makyo makyo 82 Apr 21 17:27 s4*
would allow case 1 to succeed:
Code:
$ ./s4
Hello, world.
(The "$ " is a prompt, and the "./" part means "the file in the current directory".)
I usually make the first line in my file a special line, so that my script files look like:
Code:
#!/bin/sh
# @(#) s4 Demonstrate command file, omitting shebang line.
echo " Hello, world."
There are variations, and note the comments from druuna about shells.
Best wishes ... cheers, makyo
(edit 1, 2: typos )