I'm trying to escape the following code with the echo
command but I keep getting the actual octet and not the emoji.
Also where could I find the octet values of the emojis? I seem to always find the UTF-8
values.
#!/usr/bin/env bash
UNICORN='\360\237\246\204\n'
FIRE=''
# this does not work when I run the script
printf '\360\237\246\204\n'
printf "Riding a ${UNICORN:Q}"
echo "Riding a ${UNICORN:Q}" #[Fails]: how to extract the actual emoji?
EDIT_1: Just updating the code after reading comments
#!/usr/bin/env bash
# Note: use hexdump -b to get one-bye octal display
UNICORN_UTF8=$'\360\237\246\204'
printf "U1F525\n"|hexdump -b # [ASK]: How to translate the return value to a valid UTF8 ?
FIRE_UTF8=$'\125\061\106\065\062\065\012'
echo "Riding a ${UNICORN_locale_encoding}"
echo "${UNICORN_UTF8} + ${FIRE_UTF8}"
EDIT_2: Posting final code. It sort of works.
#!/usr/bin/env bash
# Author:
# Usage:
# Note: use hexdump -b to get one-bye octal display of the emoji (needed for when ≠ computers use ≠ commandLine tools)
# Ex: printf "U1F525\n"|hexdump -v -e '"\\" 1/1 "%03o"' ; echo
UNICORN_UTF8=$'\360\237\246\204'
FIRE_UTF8=$'\xF0\x9F\x94\xA5'
LEAVE_SPACE=\^[a-zA-Z0-9_]*$\
echo "Riding an ${UNICORN_UTF8} ${LEAVE_SPACE} out of a ${FIRE_UTF8} ${LEAVE_SPACE} house."
printf
? Also see this relevant question https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo – Daniele Santi Sep 06 '18 at 09:51\octet
and even\n
areprintf
syntax. what makes you expectecho
knos ho to interpret them? – Philippos Sep 06 '18 at 09:54printf
andecho
behaved the same. New to thisbash
and scripting.@MrShunz, main reason is because I would like to use it on an script, and my current scripts has
– intercoder Sep 06 '18 at 14:02echo "Ready to git-some and sync your local branches to the remote counterparts ?"
printf U1F525
outputsU1F525
, 0125 is the code for U. With bash-4.2+ useprintf '\U1F525'
as already shown in answers to both your questions. – Stéphane Chazelas Sep 06 '18 at 14:42