How to create a ____________ in 100% in shell script?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm not sure what you really want but I think you could make use of the dialog command. And if you want to generate a line you just make use of echo with the use of substring expansion I think. That's less expensive compared to multiple calls to echo in a loop.
Code:
LINE=__________
for (( I = 1; I <= 5; ++I )); do ## or "for {1..5}; do" in newer Bash probably 4.0
LINE=${LINE}${LINE} # or LINE+=${LINE} in Bash 3.1+
done
echo "${LINE:0:100}" ## Change 100 to any number depending on the needed line's length
echo "My Application title"
echo "${LINE:0:100}"
printf -v line '%.*d\n' "$COLUMNS"
echo "${line//0/_}"
"*" is a printf format feature that gets substituted by the numerical value of the first non-format argument.
You only need to ensure that the COLUMNS variable or similar is available.
I'm trying to get the number of columns or lines of my terminal but the variables COLUMNS / LINES are always empty http://mywiki.wooledge.org/BashFAQ/091
Finally, as printed above it requires bash/ksh features, but it could be replicated in other shells with command substitution and something like tr.
Just consider that printf -v is a new feature available to versions of Bash not earlier than 4.0 so consider using it if compatibility to earlier versions is not necessary.
As for Xeratul's suggestion to tput, you could also have stty to get the number of columns:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.