print colors and new lines
Print text in color, and print new lines from a string, which plain echo may not do.
shell
steps
-
printf 'one\ntwo\n'new lines, the same in every shell
-
echo -e 'one\ntwo'the same with bash's echo
-
printf '\033[31mred\033[0m\n'red text, then back to normal
-
printf '\033[1;32mOK\033[0m\n'bold green
-
echo "$(tput setaf 4)blue$(tput sgr0)"colors by name of the terminal's capability
notes
- Colors 30 to 37: black, red, green, yellow, blue, magenta, cyan, white; 1; makes them bold.
commands used
printftput
Each has a page in lore: lore printf opens it.
add a folder to the path
Let the shell find programs in a folder, for good, and reload the settings without logging out.
add to the end of a file
Add lines to a file without replacing it, also to a file only root can write.
argument list too long
"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.
ask for input in a script
Ask yes or no, read a password without showing it, or wait for an answer with a time limit.