Start writing the shell script in Ubuntu Linux Operating System with #! /bin/bash or #!/bin/sh or #!/usr/bin/sh, meaning that the shell script file gets executed by "sh" which is located in the "bin" directory. It is a standard recommendation from the Linux Distributions to write this line, without it the script file runs successfully. Save the shell script as " filename.sh". Sh depicts files with scripts, and system blocks all permissions in the Linux Operating System to make the file secure; therefore, it is not advisable by Linux Distributions to save the file in a text format. Insert permissions to your script file to enable users of different levels to read, write and execute a script file, by keying the following line in Ubuntu:
chmod u+x sayH
<Enter>
./sayH
<Enter>
Ubuntu - Shell script to execute/run
Issue
I am writing a simple shell script in Ubuntu Linux.
$ vi sayH
echo "Your first name please:"
read fname
echo "Hello $fname, Lets be friend!"
How to execute and Run in Linux??
Solution
First, append "#! /bin/bash" in top of file:
#! /bin/bash
echo "Your first name please:"
read fname
echo "Hello $fname, Lets be friend!"
Then:
chmod u+x sayH
<Enter>
./sayH
<Enter>
Note
Thanks to
jipicy for this tip on the forum.
See also
Knowledge communities.
Published by
aakai1056 -
Latest update by Virginia Parsons