# Help with variable assignment

**URL:** <https://community.unix.com/t/help-with-variable-assignment/278023>\
**Category:** Shell Programming and Scripting\
**Created:** [November 26, 2010, 1:49am UTC](https://community.unix.com/t/help-with-variable-assignment/278023 "2010-11-26T01:49:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul9909](https://community.unix.com/user_avatar/community.unix.com/rahul9909/32/6487_2.png) [@rahul9909](https://community.unix.com/u/rahul9909)\
**Post date:** [November 26, 2010, 1:49am UTC](https://community.unix.com/t/help-with-variable-assignment/278023/1 "2010-11-26T01:49:50Z")

</div>

Hi,

In AIX I have a variable with , (coma) separated values assigned to it like shown below

var1=apple,boy,chris  
i want to convert this to  
var1='apple','boy','chris'

the number of values assigned to var1 might change and it could be from 1 to n

any suggestions please?

---

<div class="post-metadata">

**Author:** ![IND123](https://community.unix.com/letter_avatar/ind123/32/5_5575768a8748004e209b776fc1b2916d.png) [@IND123](https://community.unix.com/u/IND123)\
**Post date:** [November 26, 2010, 2:17am UTC](https://community.unix.com/t/help-with-variable-assignment/278023/2 "2010-11-26T02:17:14Z")

</div>

quick solution:

```auto
var1=apple,boy,chris

var1=`echo $var1 | sed "s/,/','/g"`

var1=`echo "'"$var1"'"`

echo $var1 # Now it holds : 'apple','boy','chris'

```

---

<div class="post-metadata">

**Author:** ![rahul9909](https://community.unix.com/user_avatar/community.unix.com/rahul9909/32/6487_2.png) [@rahul9909](https://community.unix.com/u/rahul9909)\
**Post date:** [November 26, 2010, 2:30am UTC](https://community.unix.com/t/help-with-variable-assignment/278023/3 "2010-11-26T02:30:51Z")

</div>

Thank you !!

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [November 26, 2010, 2:38am UTC](https://community.unix.com/t/help-with-variable-assignment/278023/4 "2010-11-26T02:38:11Z")

</div>

```nohighlight
var1=$(echo "$var1" | sed "s/[^,]*/'&'/g")

```
