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 :-)
Linux* BashScripting Languages

Avatar of undefined
Last Comment
woolmilkporc
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

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!
Linux
Linux

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo