Bash parameter separator

I am trying to get 1:2:3:4:5:6:7:8:9:10 using parameter extension {1..10} and pattern matching:

 $ var=$(echo {1..10}) $ echo ${var// /:} 1:2:3:4:5:6:7:8:9:10 

Is there a more elegant way (single line) for this?

+6
source share
3 answers

Agreeing with @choroba's comment on elegance, here are some other contemplative things:

 # seq is a gnu core utility seq 1 10 | paste -sd: # Or: seq -s: 1 10 # {1..10} is bash-specific printf "%d\n" {1..10} | paste -sd: # posix compliant yes | head -n10 | grep -n . | cut -d: -f1 | paste -sd: 
+3
source

Elegance in the eye of the beholder:

 ( set {1..10} ; IFS=: ; echo "$*" ) 
+8
source

Another possibility:

 echo {1..9}: 10 | tr -d ' ' 
+1
source

Source: https://habr.com/ru/post/945706/


All Articles