Question: Creating A Script In Vi Now we re ready to use vi to actually create our script. 1 Create an empty file using vi called

Creating A Script In Vi
Now were ready to use vi to actually create our script.
1 Create an empty file using vi called "ops_script.sh."
2 Enter Insert Mode and type the following line:
#!/bin/bash
This is called a Hash-Bang or shebang. It is optional for a script using the default interpreter, but is
considered good practice to always include it. It tells the shell which interpreter to use to run the
script. If left out it will use the default interpreter set up on the system. This can cause the script to
run differently if it is different than the machine it was created on. There are many interpreters available.
In the case we are calling the bash interpreter. Scripts can be also be used for other interpreters
like python, perl, ruby, php, etc.. For example, you might see #!/bin/perl. A shebang
is not optional for these interpreters.
3 A# by itself begins a comment. Place a comment with your name on the second line of the script.
4 The echo command, as we have already seen, sends what follows to the screen when the script runs.
Add this line:
echo "Script is running"
5 Save and exit your script and vi.
6 The default permissions on the script do not include execute. You can read and write but not execute.
If you tried to run it now it would give you a permissions error.
-5-
7 To change the permissions you use the chmod command.
8 At the shell prompt, enter the command:
chmod 755 ops_script.sh
9 The 755 sets the permissions for your user to read, write, and execute. It sets permissions for all
other users to read and execute only. If you want your script to be private (i.e., only you can read,
write, and execute), use 700 instead. A complete list of permissions options can be found in the
manual (man) page for chmod.
10 When running scripts you need to specify a path. In this case we want it to run from the current directory
so we will use ./. Enter the following at your shell prompt to run the script:
./ops_script.sh

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!