Python Variables and Assignment A variable is a name, which represents a value. To understand it, open a Python terminal and run below command. id = 10 You will not see any result on screen. Then what happens here? This is an assignment statement, where id is a variable and 10 is the value assigned to the variable. A single equal (=) is an assignment operator. Where left side of the operator is the variable and right side operator is a value. Once a value is assigned to the variable,…
Read MoreTag: variables
Concatenate Two Strings
Shell Script to Concatenate Two Strings Brief: This example will help you to concatenate two or more strings variable in a bash script. This tutorial helps you with multiple shell script examples of concatenating strings in a shell script. The first example is a general way to concatenate variables of string. You can simply write all the variable one after another:
1 2 3 4 5 6 7 8 9 | #!/bin/bash # Shell program to concatenate two strings in variable str1="Welcome " str2="TecAdmin!" str3=$str1$str2 echo $str3 |
Output: Welcome TecAdmin! Another Example You can also use += operator to concatenate two strings and store results in the first string.
1 2 3 4 5 6 7 8 | #!/bin/bash str1="Welcome " str2="TecAdmin!" str1+=$str2 echo $str1 |
Output: Welcome TecAdmin! One More…
Read MoreBash – Quotes
Quotes in Bash This is a standard practice to quote the string in any programming language. Quotes are used to deal with the texts, filenames with a space character. Read this tutorial to understand the differences between single quote and double quotes. Quote with String While working with simple texts and string, there are no different in using a single quote or double quote.
1 2 3 4 5 6 7 | #!/bin/bash echo 'String in single quote' echo "String in double quote" mkdir 'Dir 1' mkdir "Dir 2" |
The above script will run without any error and print the messages and create both directories. Quote with Variables Just remember that the shell variable…
Read MoreBash – Variables
Variables in Bash The bash variables are the same as other programming languages. You don’t need to specify the type of variable in bash scripting. Read below example. #!/bin/bash NAME=”TecAdmin Tutorials” echo $NAME launchdate=”Feb 08, 2013″ echo $launchdate Global vs Local Variables Global variables are accessible anywhere in the script. Where Local variables are accessible in scope only. For example, a variable that is used inside a function only.
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/bash #Define bash global variable GLOBAL_VAR="global variable value" function hello { #Define bash local variable local LOCAL_VAR="local variable value" echo $LOCAL_VAR echo $GLOBAL_VAR ## This will accessible here } echo $LOCAL_VAR ## This will not accessible here echo $GLOBAL_VAR |
System Variables System variables are responsible to define the aspects of the shell. These variables are maintained by bash itself.…
Read More