Join
the community
Sign-up
Ask a question »

Ubuntu - Shell script to execute/run

April 2013

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
This document entitled « Ubuntu - Shell script to execute/run » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.
Receive our newsletter

health.kioskea.net

Ubuntu tutorials
Ubuntu - Open/Close the CD-rom tray in command line