Add backslash and apostrophe to string in variable.

Hi All

I want to add backslash and apostrophe to variable in my bash script.

I have my variable:

USER_LIST=USER1,USER2,USER3

and I want something like this:

USER_LIST_DEL=/'USER1/',/'USER2/',/'USER3/'

any ideas ??

How about

USER_LIST_DEL=$(IFS=,; for u in $USER_LIST; do echo -n "/'$u/'",; done)

or

USER_LIST_DEL=/\'${USER_LIST//,//\',/\'}/\'
1 Like