How to use IFS to get output of range in comma separator in bash?

beer9
beer9 used Ask the Experts™
on
I would like to have output like below

ns2.com,ns3.com,ns4.com,ns5.com,ns6.com,ns7.com,ns8.com,ns9.com,ns10.com,

Open in new window


which I am able to get from below command in bash

$printf '%s,' ns{2..10}.com
ns2.com,ns3.com,ns4.com,ns5.com,ns6.com,ns7.com,ns8.com,ns9.com,ns10.com,

Open in new window


I am wondering if I can get something like this using IFS (Internal Field Separator) in bash

something like
IFS=, ns{2..10}.com

Open in new window


which obviously doesn't work. Appreciate any suggestion :-)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
Distinguished Expert 2018
Commented:
IFS means Input Field Separator and can be used for splitting fields...
Like so:
 printf '%s,' ns{2..10}.com | (IFS=, read a b c d e f ; echo $a / $b / $c / $d / $e / $f )

Yielding:
ns2.com / ns3.com / ns4.com / ns5.com / ns6.com / ns7.com,ns8.com,ns9.com,ns10.com,

So what are you trying to accomplish exactly?
Most Valuable Expert 2013
Top Expert 2013

Commented:
Usually shell builtins do not take IFS/OFS settings into account, at least bash's brace expansion definitely doesn't.

In order to avoid the comma at the end you could try this:

echo  ns{2..10}.com | tr " " ","

As I said, no chance with IFS, unfortunately!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial