Take the 2-minute tour ×

Possible Duplicate:
Split string based on delimiter in bash?

i have a shell script which call by php and pass a variable ($1)

When i using MYVAR = $1, and echo MYVAR is not working

how can i assign this variable ($1) to another variable and split it with delimiter "," and convert it into a array for looping?

share|improve this question
it cant solve my problem "When i using MYVAR = $1, and echo MYVAR is not working" –  user192344 Dec 19 '11 at 2:14
Is that the literal notation in your script? Wouldn't that give you an error message? –  mario Dec 19 '11 at 2:16
it should be MYVAR=$1 with no spaces anyways. –  Marc B Dec 19 '11 at 2:17
add comment

marked as duplicate by mario, Marc B, ajreal, Jasper, Andrew Barber Dec 20 '11 at 1:25


1 Answer

up vote 4 down vote accepted

Well, guessed answer in absence of code.

Variable assignments in shell scripts must be:


Spaces around are incorrect:

  MYVAR = $1

And the echo must output an actual variable, using the $ prefix:

  echo $MYVAR

Not just the literal string:

  echo NOVAR
share|improve this answer
add comment
