The document provides an introduction to variables in Bash shell scripting, explaining their importance for storing data. It distinguishes between system variables, which are predefined by the operating system, and user-defined variables, which are created by the user following specific naming rules. Additionally, it outlines the rules for defining user-defined variables, including naming conventions and how to assign values.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views4 pages
Introduction to Variables
The document provides an introduction to variables in Bash shell scripting, explaining their importance for storing data. It distinguishes between system variables, which are predefined by the operating system, and user-defined variables, which are created by the user following specific naming rules. Additionally, it outlines the rules for defining user-defined variables, including naming conventions and how to assign values.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4
Variables
NarendraP
Learn How to Automate Common Tasks with Bash Shell Scripting
Introduction to Variables Variables are useful to store data in shell scripts and Later we can use them if they required. Simple Variable: x=4 Default value of a variable is Empty/Nothing In Linux Shell Scripting, there are two types of variables: System Variables: Created and maintained by Operating System itself. This type of variables are defined in CAPITAL LETTERS. We can see them by using set command Example: HOME, USER… User Defined Variables: Created and maintained by the user. This type of variables are defined in lower letters. But we can also take combination of upper and lower case letters.
Learn How to Automate Common Tasks with Bash Shell Scripting
Rules to Define User Defined Variables Variable Name should contain only a-z or A-Z, 0-9 and _ characters. Variable Name length should be less than or equal to 20 characters. Variable Names are case sensitive. Means x and X are different. Don’t Provide space on either sides of equal symbol while defining variables Ex: x=4 is valid x =4 or x = 4 or x= 4 are invalid No need to declare variable type, Automatically it will take care while executing commands or scripts. Use quotes for the data if data consist of spaces We can store the output of a command into a variable as follows: anyVariable=$(command) anyVariable=`command` We can assign one variable value/data into another using: Name=“Shell Scripting” NewName=$Name NewName=${Name}
Learn How to Automate Common Tasks with Bash Shell Scripting