Link to home
Start Free TrialLog in
Avatar of beer9
beer9Flag for India

asked on

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

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 :-)
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!