1

I have seen one syntax in bash script for variable assignment. probably i am not getting what is use of it.

Syntax is :

VarName=()

Thanks.

2 Answers 2

2

The bash shell has simple variables and one-dimensional array variables. That one is simply creating an empty array.

You can see the effect in the following transcript which creates arrays of varying sizes and shows you their size:

pax> x=(1 2 3 4 5) ; echo ${#x[@]}
5
pax> x=(1) ; echo ${#x[@]}
1
pax> x=() ; echo ${#x[@]}
0
Sign up to request clarification or add additional context in comments.

2 Comments

@Axit, I'd prefer you to accept my answer because it was right rather than quick but, since it's both right and quick, I'll take it :-)
i first checked that it was right or not. and then i commented like this. as Stackoverflow only allows to accept answer after 15 mins. :)
0

Try reading the documentation. See https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters

VarName=1
VarName="two"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.