We help IT Professionals succeed at work.

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

beer9 asked
Last Modified: 2017-04-08
I would like to have output like below


Open in new window

which I am able to get from below command in bash

$printf '%s,' ns{2..10}.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 :-)
Watch Question

Software Engineer
Distinguished Expert 2019
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
Most Valuable Expert 2013
Top Expert 2013

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!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions