Monday 26 December 2016

php - shell script - how to split a string with delimiter ","










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?


Answer



Well, guessed answer in absence of code.



Variable assignments in shell scripts must be:



  MYVAR=$1



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

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...