Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

PDF notes for BCA 2nd semester exam

Rating
-
Sold
-
Pages
9
Uploaded on
23-06-2024
Written in
2023/2024

In this I will provide you notes of operating system, English, computer architecture and organisation, data base management system, English and important questions also by reading this you will gureented pass

Institution
Course

Content preview

BASH SCRIPTING

Bash Array
An array can be defined as a collection of similar type of elements. Unlike most of the programming languages,
arrays in bash scripting need not be the collection of similar elements. Since Bash does not discriminate the
string from a number, an array may contain both strings and numbers.

Bash does not provide support for the multidimensional arrays; we cannot have the elements which are arrays
in themself. Bash provides support for one-dimensional numerically indexed arrays as well as associative
arrays. To access the numerically indexed array from the last, we can use negative indices. The index of '-1'
will be considered as a reference for the last element. We can use several elements in an array.


Bash Array Declaration
Arrays in Bash can be declared in the following ways:

Creating Numerically Indexed Arrays

We can use any variable as an indexed array without declaring it.

To explicitly declare a variable as a Bash Array, use the keyword 'declare' and the syntax can be defined as:

declare -a ARRAY_NAME

where,

ARRAY_NAME indicates the name that we would assign to the array.

Note: Rules of naming a variable in Bash are the same for naming an array.

A general method to create an indexed array can be defined in the following form:

ARRAY_NAME[index_1]=value_1

ARRAY_NAME[index_2]=value_2

ARRAY_NAME[index_n]=value_n

where keyword 'index' is used to define positive integers.

Creating Associative Arrays

Unlike numerically indexed arrays, the associative arrays are firstly declared. We can use the keyword 'declare'
and the -A (uppercase) option to declare the associative arrays. The syntax can be defined as:

declare -A ARRAY_NAME

, A general method to create an associative array can be defined in the following form:

declare -A ARRAY_NAME

ARRAY_NAME[index_foo]=value_foo

ARRAY_NAME[index_bar]=value_bar

ARRAY_NAME[index_xyz]=value_xyz

where index_ is used to define any string.

We can also write the above form in the following way:

declare -A ARRAY_NAME

ARRAY_NAME=(

[index_foo]=value_foo

[index_bar]=value_bar

[index_xyz]=value_xyz

)


Bash Array Initialization
To initialize a Bash Array, we can use assignment operator (=), by specifying the list of the elements within
parentheses, separated by spaces like below:


ARRAY_NAME=(element_1st element_2nd element_Nth)

Note: Here, the first element will have an index 0. Also, there should be no space around the assignment operator (=).


Access Elements of Bash Array
To access the elements of a Bash Array, we can use the following syntax:

echo ${ARRAY_NAME[2]}


Print Bash Array
We can use the keyword 'declare' with a '-p' option to print all the elements of a Bash Array with all the indexes
and details. The syntax to print the Bash Array can be defined as:

declare -p ARRAY_NAME

Written for

Institution
Course

Document information

Uploaded on
June 23, 2024
Number of pages
9
Written in
2023/2024
Type
Class notes
Professor(s)
Mr pritam lata
Contains
All classes

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
tanmaysharma

Also available in package deal

Get to know the seller

Seller avatar
tanmaysharma Pandit Deendayal Upadhyaya shekhawati University
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
2
Last sold
-
Notes for BCA

I this I will provide you notes for BCA 2nd semester exam

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions