what will be the echo output in this scenario
cmd ()
{ xyz=(abc def ghi jkl mno) echo ${xyz[$2]} } I am sending some numbers from a function cmd 12 59 30 25 I am bit confused what output did the echo would throw? I am new to shell scripting. I am sorry if this question is not valid. |
The echo won't show anything!
xyz will be an array where xyz[0]='abc' , xyz[1]='def', xyz[2]='ghi' .....etc by calling the function with arguements 12, 59, 30 and 25, you are saying that $1=12, $2=59, $3=30 and $4=25 You then try to echo the 60th entry in the xyz array ( or xyz[59] ) which it doesn't have so there is nothing to display. if you called the cmd function with cmd 2 1 3 0 it would have shown xyz[1] or "def" I hope this is clear. |
Quote:
|
Also you can put set -x at the top of your code to have the shell show you what it is doing.
|
All times are GMT -5. The time now is 08:55 AM. |