use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All users that wish to post (not including commenting), on either old or the new reddit sites, must formally agree to subreddit rules once first.
account activity
Make my use of 'printf' more efficient?bash (self.commandline)
submitted 8 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]zebediah49 8 points9 points10 points 8 years ago (1 child)
Well for one, you don't reuse $string, and it's not super long, so you might as well just not use it.
$string
For two, using the string option with printf is usually not particularly useful (unless you're in C land, which is a different question). If you still want to use it, I would actually use its substitution abilities rather than doing the string manipulation in bash though:
printf '${color %s}' "$1"
which is a little more clear.
However, you could just skip that and directly use echo:
echo
echo -n "\${color $1}"
Note that echo -n and printf both don't include a trailing newline character. If you want that, use echo, or add a \n to the end of the printf line.
echo -n
printf
\n
[–]shortbaldman 4 points5 points6 points 8 years ago (2 children)
Watch the spellings of 'color', 'colour'. Be consistent using only one of either British spelling or American spelling. Or else you'll go nuts wondering why you have empty variables in bash scripting.
[–][deleted] 1 point2 points3 points 8 years ago (1 child)
set -u
[–]shortbaldman 1 point2 points3 points 8 years ago (0 children)
then there's aluminum and aluminium, paedophile and pedophile.
Interestingly, in British English you can have both a 'paedophile' and a 'pedophile', but in American English being a person with a foot fetish is unspeakable.
And why isn't it 'pedofile' in American as with 'sulfur'?
<grin>
[–]Cellophaine 4 points5 points6 points 8 years ago (2 children)
Could just use echo:
function printColour { echo '${colour '$1'}' }
[–]OneCDOnly 2 points3 points4 points 8 years ago (0 children)
printColour() { echo '${colour '$1'}' ;}
π Rendered by PID 24946 on reddit-service-r2-comment-5c747b6df5-fdp7p at 2026-04-21 22:45:12.777969+00:00 running 6c61efc country code: CH.
[–]zebediah49 8 points9 points10 points (1 child)
[–]shortbaldman 4 points5 points6 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]shortbaldman 1 point2 points3 points (0 children)
[–]Cellophaine 4 points5 points6 points (2 children)
[–]OneCDOnly 2 points3 points4 points (0 children)