Ubuntu – Shell script to execute/run

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>

Advertisements

About zephyr9000

Happy sailer
This entry was posted in scripts, shell and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s