Shell Scripting-2

Shell Scripting-2

·

2 min read

Table of contents

No heading

No headings in the article.

File name conventions

  • file name can be a maximum of 225 characters

  • the name may contain alphabets(a-z or A-z), digits(0-9), dots(.), and underscores(_)

  • system commands or Linux reserve words can not be used for file names

  • the file system is case-sensitive

    ex: var_01 etc.,

comments

use of comments

  • it is for more understandability and readability

  • it is used for escape from the code

  • shell script has two types of comments

single line comment

#this is a single line comment

multi-line comment

<< Suma

hi

hello

Suma

output

Variable

A variable is a character string to which we assign a value. the value assigned could be a number, text, file name, device, or any other type of data

  • it is a storage. it can store the value

there are two types of variables

a) system define variables - these are created and maintained by the system i.e Bash

env or printenv to see all system-defined variables usually it shows

VARIABLE_NAME= $VARIABLE_VALUE

ex: FRUIT="apple"

here the variable is defined as FRUIT and the value that has been assigned to the FRUIT variable is "apple"

The value stored in a variable can be accessed by prefixing its name with the dollar ($) sign.

ex: #!/bin/sh

FRUIT = “Pineapple”

echo “My favorite fruit is $FRUIT.”

output: My favorite fruit is Pineapple

echo $shell - it is going to display variable value

b) user-defined variables

as a user, he/she is going to create a variable and also going to assign the values

user-defined vars --(user-defined and set the values)

a = 10 echo $a echo" a variable value is:"${a}

b = 20 echo $b echo" b variable value is:"${b}

c =30 echo $c echo" c variable value is:"${c}

name=Kalyan echo $Kalyan echo "name variable value is:"${name}