• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to write a simple shell script and how to use Variables in shell script

{{postValue.id}}

To write a simple shell script and how to use Variables in the shell script

A variable is a character string to which we relegate an esteem. The esteem doled out could be a number, content, filename, gadget, or some other kind of information.

Let’s First Create a Simple shell script to print a statement

[root@linuxhelp11 ~]# vim simple.sh
#!/bin/bash
echo " This is shell script "

Now make the file as executable format as follows

[root@linuxhelp11 ~]# chmod +x simple.sh

Run the shell script using the “sh” and see the output

[root@linuxhelp11 ~]# sh simple.sh
This is shell script

Now let’s see another example for creating a Text file using the script Open a File and type the command to create a text file

[root@linuxhelp11 ~]# vim simple.sh
#!/bin/bash
touch /opt/newfile.txt

Verify the folder before execting the script

[root@linuxhelp11 ~]# ls /opt
Rh

Now lets execute the script and verify

[root@linuxhelp11 ~]# sh simple.sh
[root@linuxhelp11 ~]# ls /opt/
newfile.txt  rh

A File has been created using a script

VARIABLES

A variable is a character string to which we assign a value. The value assigned could be a number, text, filename, device, or any other type of data. A variable is nothing more than a pointer to the actual data. The shell enables you to create, assign, and delete variables.

Syntax:
VARIABLE_NAME="  value "
  > Variables are case sensitive
  > VariableName  must be in uppercase

Let’s see an example Create a file named variable.sh and add a variable as follows

[root@linuxhelp11 ~]# vim variable.sh
#!/bin/bash
VAR=script
echo "Shell ${VAR}ing is Interesting"

Now make the file executable and verify

[root@linuxhelp11 ~]# chmod +x variable.sh
[root@linuxhelp11 ~]# sh variable.sh
Shell scripting is Interesting

So as you see the Variable has been printed as an output after the exection And if you want to remove variable but not syntax just use the following script and print without variable


[root@linuxhelp11 ~]# vim variable.sh
#!/bin/bash
VAR=script
echo "Shell $VARing is Interesting"
[root@linuxhelp11 ~]# sh variable.sh
Shell  is Interesting

Tags:
jackson
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 2 )

Q

What is the Rexloader?

A

In the official repositories of major Linux distributions are also different download manager (like Uget, Aria2 etc.),

Q

What are the supported files for downlaod?

A

Rexloader allows us to download our files faster thanks to the multithreaded features of registration and calculation of MD5 hash, SHA1 Also included is support for downloading files via ftp or torrent files.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help David Lopez Guillen ?
Ayuda urgente instale SSL para servidor Opensuse y ahora no funciona tengo servicio web

hola segui este tutorial para tener un certificado ssl y ahora no se ve mi app en la red, espero alguien pueda ayudarme, tengo M9oodle en3.5 en un servidor open suse y ahora no funciona por favor ayuda.

https://www.linuxhelp.com/how-to-create-ssl-certificate-in-opensuse

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.