Ubuntu - Shell script to execute/run

September 2017

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>

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.

Related

Published by aakai1056. Latest update on March 17, 2012 at 04:55 PM by Virginia Parsons.
This document, titled "Ubuntu - Shell script to execute/run," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).