Reputation: 8170
I'm trying to get 1:2:3:4:5:6:7:8:9:10
using parameter expansion {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 (one-liner) to do this?
Upvotes: 9
Views: 1814
Reputation: 241671
Agreeing with @choroba's comment about elegance, here are some other beholdables:
# 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:
Upvotes: 5
Reputation: 241748
Elegance is in the eye of the beholder:
( set {1..10} ; IFS=: ; echo "$*" )
Upvotes: 11