ã16é²æ°ã®0xAAã£ã¦ã10é²æ°ã ã¨ã©ããªãï¼ãã¨ãæããã¨ã¯ããããã¾ããã*1ããããªã¨ããperlã®ã¯ã³ã©ã¤ãã¼ã§ã
$ perl -e 'print hex("AA")'
170
$
ã¨ããã¦ã¾ããã
ã§ããbashã使ã£ã¦ãããªãprintfã¨ããã³ãã³ãï¼çµã¿è¾¼ã¿ã³ãã³ã*2ï¼ããããã§ãããã
$ help printf
printf: printf [-v var] format [arguments]
printf formats and prints ARGUMENTS under control of the FORMAT. FORMAT
is a character string which contains three types of objects: plain
characters, which are simply copied to standard output, character escape
sequences which are converted and copied to the standard output, and
format specifications, each of which causes printing of the next successive
argument. In addition to the standard printf(1) formats, %b means to
expand backslash escape sequences in the corresponding argument, and %q
means to quote the argument in a way that can be reused as shell input.
If the -v option is supplied, the output is placed into the value of the
shell variable VAR rather than being sent to the standard output.$
printfã«ã¤ãã¦ã¯ãããã®ã·ã§ã«ã»ã¯ã³ã©ã¤ãã¼ããã£ããå½¹ç«ã£ãï¼ printfã³ãã³ãã§è¶ ç°¡æãã³ãã¬ã¼ããã§ããã³ãã¬ã¼ãã£ã½ãå¦çã«ä½¿ãããã¨ãç´¹ä»ãã¾ããããã¡ããã%d ã¨ãããã©ã¼ãããæå®åã使ããã®ã§ï¼
$ printf %d 0xAA
170
$
%x ã使ãã°ï¼
$ printf %x 170
aa
$
printfã§ã¯ã\n ã¨ããå½¢ã®æ¹è¡ã使ããã®ã§ãechoãã便å©ã§ãã
$ echo "Hello\nworld"
Hello\nworld$ printf "Hello\nworld"
Hello
world
$
echo㧠\n ã使ããããªãï¼
$ echo $'Hello\nworld'
Hello
world$