How to print value of a variable (which can be "-n" or "-e") in bash? -


How to print "-n", "-e" or "-neeenen" from the bass (finally a new line Without, without applying external programs)?

question = "- n"

echo -n "$ Q" #failed

echo - "$ Q" #failed

cat #Failed, external program also starts

printf - '% s' "$ Q" # success, but external program

In Bash, printf is a builtin, therefore not apply to external programs is done.

  $ help printf printf: printf [-v var] format [arguments]  

FORMAT control under printf format and prints FORMAT one There is a character string in which there are three types of objects: plain character, which are copied only to standard output, Character Asec sequence that is converted and copied into standard output, and format specification, each of which is next printed next argument Causes . In addition to the standard printf (1) formats,% b means that the backslash escape sequence should be expanded in this argument, and% q means to argue in a way that can be reused as a shell input Could. If the -v option is provided, the output is kept in the value of the shell variable instead of the output to the output, to the output the output is sent to the output.


Comments