0
Thanks

A few words of thanks would be greatly appreciated.

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>

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.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team

Published by . Latest update on 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 (https://ccm.net/).

0 Comments