Could you please tell me what the equivalent BASH code for the following C++ snippet would be:
std::cout << std::setfill('x') << std::setw(7) << 250;
The output is:
xxxx250
Thanks for the help!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re on Linux, it has a
printfprogram for just this purpose. Other UNIX variants may also have it.Padding a numeric with
xis not really on of its use cases but you could get the same result with:That outputs the 250 with space padding, then uses the
trtranslate utility to turn those spaces intoxcharacters.If you’re looking for a
bash-only solution, you can start with:If you want a generalised solution, you can use this function
fmt, unit test code is included:This outputs:
and you’re not limited to just printing them, you can also save the variables for later with a line such as: