简体   繁体   中英

Echo character based on variable value (linux)

My aim is to echo a character, for example # , based on a value such as num=6 and it must print # 6 times on the screen.

Not sure how to get this.

You could do something like

 printf '#%.0s' {1..6}

or, in the more general case,

 printf '#%.0s' $(seq 1 $num)
printf "%*s" "$num" " " | tr " " "#"

要么

yes '#' | head -"$num" | tr -d "\n"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM