Problems escaping a variable when using echo
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
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='360237246204n'
FIRE=''
# this does not work when I run the script
printf '360237246204n'
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=$'360237246204'
printf "U1F525n"|hexdump -b # [ASK]: How to translate the return value to a valid UTF8 ?
FIRE_UTF8=$'1256110665626512'
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 "U1F525n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
UNICORN_UTF8=$'360237246204'
FIRE_UTF8=$'xF0x9Fx94xA5'
LEAVE_SPACE=^[a-zA-Z0-9_]*$
echo "Riding an $UNICORN_UTF8 $LEAVE_SPACE out of a $FIRE_UTF8 $LEAVE_SPACE house."
bash scripting
New contributor
 |Â
show 1 more comment
up vote
2
down vote
favorite
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='360237246204n'
FIRE=''
# this does not work when I run the script
printf '360237246204n'
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=$'360237246204'
printf "U1F525n"|hexdump -b # [ASK]: How to translate the return value to a valid UTF8 ?
FIRE_UTF8=$'1256110665626512'
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 "U1F525n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
UNICORN_UTF8=$'360237246204'
FIRE_UTF8=$'xF0x9Fx94xA5'
LEAVE_SPACE=^[a-zA-Z0-9_]*$
echo "Riding an $UNICORN_UTF8 $LEAVE_SPACE out of a $FIRE_UTF8 $LEAVE_SPACE house."
bash scripting
New contributor
3
Welcome to this site! Any reason why you don't want to useprintf
? Also see this relevant question unix.stackexchange.com/questions/65803/â¦
â Mr Shunz
Sep 6 at 9:51
2
This is a follow-on question to unix.stackexchange.com/questions/466961 .
â JdeBP
Sep 6 at 9:53
1
octet
and evenn
areprintf
syntax. what makes you expectecho
knos ho to interpret them?
â Philippos
Sep 6 at 9:54
@Philippos thanks, I thought thatprintf
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 hasecho "Ready to git-some and sync your local branches to the remote counterparts ?"
â intercoder
Sep 6 at 14:02
@JdeBP correct that is the follow up question to actually all my questions here. I'm trying to incorporate emojis into my script
â intercoder
Sep 6 at 14:16
 |Â
show 1 more comment
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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='360237246204n'
FIRE=''
# this does not work when I run the script
printf '360237246204n'
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=$'360237246204'
printf "U1F525n"|hexdump -b # [ASK]: How to translate the return value to a valid UTF8 ?
FIRE_UTF8=$'1256110665626512'
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 "U1F525n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
UNICORN_UTF8=$'360237246204'
FIRE_UTF8=$'xF0x9Fx94xA5'
LEAVE_SPACE=^[a-zA-Z0-9_]*$
echo "Riding an $UNICORN_UTF8 $LEAVE_SPACE out of a $FIRE_UTF8 $LEAVE_SPACE house."
bash scripting
New contributor
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='360237246204n'
FIRE=''
# this does not work when I run the script
printf '360237246204n'
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=$'360237246204'
printf "U1F525n"|hexdump -b # [ASK]: How to translate the return value to a valid UTF8 ?
FIRE_UTF8=$'1256110665626512'
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 "U1F525n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
UNICORN_UTF8=$'360237246204'
FIRE_UTF8=$'xF0x9Fx94xA5'
LEAVE_SPACE=^[a-zA-Z0-9_]*$
echo "Riding an $UNICORN_UTF8 $LEAVE_SPACE out of a $FIRE_UTF8 $LEAVE_SPACE house."
bash scripting
New contributor
edited yesterday
Rui F Ribeiro
36.1k1271115
36.1k1271115
New contributor
asked Sep 6 at 9:45
intercoder
1276
1276
New contributor
New contributor
3
Welcome to this site! Any reason why you don't want to useprintf
? Also see this relevant question unix.stackexchange.com/questions/65803/â¦
â Mr Shunz
Sep 6 at 9:51
2
This is a follow-on question to unix.stackexchange.com/questions/466961 .
â JdeBP
Sep 6 at 9:53
1
octet
and evenn
areprintf
syntax. what makes you expectecho
knos ho to interpret them?
â Philippos
Sep 6 at 9:54
@Philippos thanks, I thought thatprintf
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 hasecho "Ready to git-some and sync your local branches to the remote counterparts ?"
â intercoder
Sep 6 at 14:02
@JdeBP correct that is the follow up question to actually all my questions here. I'm trying to incorporate emojis into my script
â intercoder
Sep 6 at 14:16
 |Â
show 1 more comment
3
Welcome to this site! Any reason why you don't want to useprintf
? Also see this relevant question unix.stackexchange.com/questions/65803/â¦
â Mr Shunz
Sep 6 at 9:51
2
This is a follow-on question to unix.stackexchange.com/questions/466961 .
â JdeBP
Sep 6 at 9:53
1
octet
and evenn
areprintf
syntax. what makes you expectecho
knos ho to interpret them?
â Philippos
Sep 6 at 9:54
@Philippos thanks, I thought thatprintf
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 hasecho "Ready to git-some and sync your local branches to the remote counterparts ?"
â intercoder
Sep 6 at 14:02
@JdeBP correct that is the follow up question to actually all my questions here. I'm trying to incorporate emojis into my script
â intercoder
Sep 6 at 14:16
3
3
Welcome to this site! Any reason why you don't want to use
printf
? Also see this relevant question unix.stackexchange.com/questions/65803/â¦â Mr Shunz
Sep 6 at 9:51
Welcome to this site! Any reason why you don't want to use
printf
? Also see this relevant question unix.stackexchange.com/questions/65803/â¦â Mr Shunz
Sep 6 at 9:51
2
2
This is a follow-on question to unix.stackexchange.com/questions/466961 .
â JdeBP
Sep 6 at 9:53
This is a follow-on question to unix.stackexchange.com/questions/466961 .
â JdeBP
Sep 6 at 9:53
1
1
octet
and even n
are printf
syntax. what makes you expect echo
knos ho to interpret them?â Philippos
Sep 6 at 9:54
octet
and even n
are printf
syntax. what makes you expect echo
knos ho to interpret them?â Philippos
Sep 6 at 9:54
@Philippos thanks, I thought that
printf
and echo
behaved the same. New to this bash
and scripting. @MrShunz, main reason is because I would like to use it on an script, and my current scripts has echo "Ready to git-some and sync your local branches to the remote counterparts ?"
â intercoder
Sep 6 at 14:02
@Philippos thanks, I thought that
printf
and echo
behaved the same. New to this bash
and scripting. @MrShunz, main reason is because I would like to use it on an script, and my current scripts has echo "Ready to git-some and sync your local branches to the remote counterparts ?"
â intercoder
Sep 6 at 14:02
@JdeBP correct that is the follow up question to actually all my questions here. I'm trying to incorporate emojis into my script
â intercoder
Sep 6 at 14:16
@JdeBP correct that is the follow up question to actually all my questions here. I'm trying to incorporate emojis into my script
â intercoder
Sep 6 at 14:16
 |Â
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
10
down vote
accepted
echo
's syntax is different from the standard C escapes as supported by printf
/awk
/$'...'
...
In standard echo
syntax, you need a leading 0
in front of the octal sequence (which can have from 1 to 3 digits)ù:
echo '360237246204'
Note that for bash
's echo
builtin to work with that, you need to enable the xpg_echo
optionò:
$ UNICORN_utf8_printf_format='360237246204'
$ UNICORN_utf8_echo='360237246204'
$ UNICORN_utf8=$'360237246204'
$ printf "$UNICORN_utf8_printf_formatn"
ð¦Â
$ printf '%sn' "$UNICORN_utf8"
ð¦Â
$ shopt -s xpg_echo
$ echo "$UNICORN_utf8_echo"
ð¦Â
Above, only $UNICORN_utf8
contains a ð¦ character, encoded in UTF8. The other ones contain sequences of backslash and digits that are meant to be expanded by the respective tools.
The %b
format of the printf
utility also understands the same sequences as echo
. %b
was actually added so we can get rid of echo
which is impossible to use portably and reliably.
$ printf '%bn' "$UNICORN_utf8_echo"
ð¦Â
See also (in zsh
and bash
ó):
UNICORN_locale_encoding=$'U1f984'
Which gets you a Unicorn encoded in the locale's encoding, which would make it work even if the locale's encoding was not UTF-8 and also had that character (probably only GB18030, where ð¦ is encoded as $'2256033066'
and where $'360237246204'
would be the encoding of é¦Âî©
(NCJK UNIFIED IDEOGRAPH-9983N<private use area-E6E9>
)).
Some printf
implementations (including GNU printf
and the printf
builtin of zsh
, ksh93
and recent versions of bash
(4.2 or above)) also support those UXXXXXXXX
escape sequences in their format argument (or arguments to %b
except with ksh93); the GNU one needs 8 digits.
ù GNU coreutils echo
and busybox echo
support ooo
with -e
as an extension (not when POSIXLY_CORRECT
is in the environment for GNU echo
)
ò other option would be to use the non-standard -e
option, but then it wouldn't work when both the posix
and xpg_echo
options are enabled, like when bash
is in UNIX compliance mode.
ó ksh93 and mksh also support that syntax, but encode in UTF-8 regardless of the locale's encoding; in current (2018) versions of FreeBSD sh
, you need U0001f984
and it only works in UTF-8 locales.
1
Most complete answer! Much appreciated, glad to see this!
â Marcus Linsner
Sep 6 at 11:11
add a comment |Â
up vote
3
down vote
$ echo $'36023723020012'
ðÂÂÂ
(that's bash
's echo
, GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu))
Or you can use the echo
binary:
$ /usr/bin/echo -e "36023723020012"
ðÂÂÂ
How did I get it? I used maulinglawns's answer above to see the emoji's octal:
$ printf "U1F600n"
ðÂÂÂ
$ printf "U1F600n"|hexdump -b
0000000 360 237 230 200 012
0000005
hexdump
:-b, --one-byte-octal one-byte octal display
EDIT: If you wanted the unicorn emoji:
$ echo $'360237246204'
ð¦Â
$ `which echo` -e '360237246204'
ð¦Â
If you want some generic way of getting the octal in that format:
printf "U1F600n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
36023723020012
The output includes the n
as 12
. The ";echo" will add a newline at the end, it's useful for when trying it on command line, else the shell prompt will be shown right after the output.
thanks for that functionhexdump -b
:)
â intercoder
Sep 6 at 14:17
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
echo
's syntax is different from the standard C escapes as supported by printf
/awk
/$'...'
...
In standard echo
syntax, you need a leading 0
in front of the octal sequence (which can have from 1 to 3 digits)ù:
echo '360237246204'
Note that for bash
's echo
builtin to work with that, you need to enable the xpg_echo
optionò:
$ UNICORN_utf8_printf_format='360237246204'
$ UNICORN_utf8_echo='360237246204'
$ UNICORN_utf8=$'360237246204'
$ printf "$UNICORN_utf8_printf_formatn"
ð¦Â
$ printf '%sn' "$UNICORN_utf8"
ð¦Â
$ shopt -s xpg_echo
$ echo "$UNICORN_utf8_echo"
ð¦Â
Above, only $UNICORN_utf8
contains a ð¦ character, encoded in UTF8. The other ones contain sequences of backslash and digits that are meant to be expanded by the respective tools.
The %b
format of the printf
utility also understands the same sequences as echo
. %b
was actually added so we can get rid of echo
which is impossible to use portably and reliably.
$ printf '%bn' "$UNICORN_utf8_echo"
ð¦Â
See also (in zsh
and bash
ó):
UNICORN_locale_encoding=$'U1f984'
Which gets you a Unicorn encoded in the locale's encoding, which would make it work even if the locale's encoding was not UTF-8 and also had that character (probably only GB18030, where ð¦ is encoded as $'2256033066'
and where $'360237246204'
would be the encoding of é¦Âî©
(NCJK UNIFIED IDEOGRAPH-9983N<private use area-E6E9>
)).
Some printf
implementations (including GNU printf
and the printf
builtin of zsh
, ksh93
and recent versions of bash
(4.2 or above)) also support those UXXXXXXXX
escape sequences in their format argument (or arguments to %b
except with ksh93); the GNU one needs 8 digits.
ù GNU coreutils echo
and busybox echo
support ooo
with -e
as an extension (not when POSIXLY_CORRECT
is in the environment for GNU echo
)
ò other option would be to use the non-standard -e
option, but then it wouldn't work when both the posix
and xpg_echo
options are enabled, like when bash
is in UNIX compliance mode.
ó ksh93 and mksh also support that syntax, but encode in UTF-8 regardless of the locale's encoding; in current (2018) versions of FreeBSD sh
, you need U0001f984
and it only works in UTF-8 locales.
1
Most complete answer! Much appreciated, glad to see this!
â Marcus Linsner
Sep 6 at 11:11
add a comment |Â
up vote
10
down vote
accepted
echo
's syntax is different from the standard C escapes as supported by printf
/awk
/$'...'
...
In standard echo
syntax, you need a leading 0
in front of the octal sequence (which can have from 1 to 3 digits)ù:
echo '360237246204'
Note that for bash
's echo
builtin to work with that, you need to enable the xpg_echo
optionò:
$ UNICORN_utf8_printf_format='360237246204'
$ UNICORN_utf8_echo='360237246204'
$ UNICORN_utf8=$'360237246204'
$ printf "$UNICORN_utf8_printf_formatn"
ð¦Â
$ printf '%sn' "$UNICORN_utf8"
ð¦Â
$ shopt -s xpg_echo
$ echo "$UNICORN_utf8_echo"
ð¦Â
Above, only $UNICORN_utf8
contains a ð¦ character, encoded in UTF8. The other ones contain sequences of backslash and digits that are meant to be expanded by the respective tools.
The %b
format of the printf
utility also understands the same sequences as echo
. %b
was actually added so we can get rid of echo
which is impossible to use portably and reliably.
$ printf '%bn' "$UNICORN_utf8_echo"
ð¦Â
See also (in zsh
and bash
ó):
UNICORN_locale_encoding=$'U1f984'
Which gets you a Unicorn encoded in the locale's encoding, which would make it work even if the locale's encoding was not UTF-8 and also had that character (probably only GB18030, where ð¦ is encoded as $'2256033066'
and where $'360237246204'
would be the encoding of é¦Âî©
(NCJK UNIFIED IDEOGRAPH-9983N<private use area-E6E9>
)).
Some printf
implementations (including GNU printf
and the printf
builtin of zsh
, ksh93
and recent versions of bash
(4.2 or above)) also support those UXXXXXXXX
escape sequences in their format argument (or arguments to %b
except with ksh93); the GNU one needs 8 digits.
ù GNU coreutils echo
and busybox echo
support ooo
with -e
as an extension (not when POSIXLY_CORRECT
is in the environment for GNU echo
)
ò other option would be to use the non-standard -e
option, but then it wouldn't work when both the posix
and xpg_echo
options are enabled, like when bash
is in UNIX compliance mode.
ó ksh93 and mksh also support that syntax, but encode in UTF-8 regardless of the locale's encoding; in current (2018) versions of FreeBSD sh
, you need U0001f984
and it only works in UTF-8 locales.
1
Most complete answer! Much appreciated, glad to see this!
â Marcus Linsner
Sep 6 at 11:11
add a comment |Â
up vote
10
down vote
accepted
up vote
10
down vote
accepted
echo
's syntax is different from the standard C escapes as supported by printf
/awk
/$'...'
...
In standard echo
syntax, you need a leading 0
in front of the octal sequence (which can have from 1 to 3 digits)ù:
echo '360237246204'
Note that for bash
's echo
builtin to work with that, you need to enable the xpg_echo
optionò:
$ UNICORN_utf8_printf_format='360237246204'
$ UNICORN_utf8_echo='360237246204'
$ UNICORN_utf8=$'360237246204'
$ printf "$UNICORN_utf8_printf_formatn"
ð¦Â
$ printf '%sn' "$UNICORN_utf8"
ð¦Â
$ shopt -s xpg_echo
$ echo "$UNICORN_utf8_echo"
ð¦Â
Above, only $UNICORN_utf8
contains a ð¦ character, encoded in UTF8. The other ones contain sequences of backslash and digits that are meant to be expanded by the respective tools.
The %b
format of the printf
utility also understands the same sequences as echo
. %b
was actually added so we can get rid of echo
which is impossible to use portably and reliably.
$ printf '%bn' "$UNICORN_utf8_echo"
ð¦Â
See also (in zsh
and bash
ó):
UNICORN_locale_encoding=$'U1f984'
Which gets you a Unicorn encoded in the locale's encoding, which would make it work even if the locale's encoding was not UTF-8 and also had that character (probably only GB18030, where ð¦ is encoded as $'2256033066'
and where $'360237246204'
would be the encoding of é¦Âî©
(NCJK UNIFIED IDEOGRAPH-9983N<private use area-E6E9>
)).
Some printf
implementations (including GNU printf
and the printf
builtin of zsh
, ksh93
and recent versions of bash
(4.2 or above)) also support those UXXXXXXXX
escape sequences in their format argument (or arguments to %b
except with ksh93); the GNU one needs 8 digits.
ù GNU coreutils echo
and busybox echo
support ooo
with -e
as an extension (not when POSIXLY_CORRECT
is in the environment for GNU echo
)
ò other option would be to use the non-standard -e
option, but then it wouldn't work when both the posix
and xpg_echo
options are enabled, like when bash
is in UNIX compliance mode.
ó ksh93 and mksh also support that syntax, but encode in UTF-8 regardless of the locale's encoding; in current (2018) versions of FreeBSD sh
, you need U0001f984
and it only works in UTF-8 locales.
echo
's syntax is different from the standard C escapes as supported by printf
/awk
/$'...'
...
In standard echo
syntax, you need a leading 0
in front of the octal sequence (which can have from 1 to 3 digits)ù:
echo '360237246204'
Note that for bash
's echo
builtin to work with that, you need to enable the xpg_echo
optionò:
$ UNICORN_utf8_printf_format='360237246204'
$ UNICORN_utf8_echo='360237246204'
$ UNICORN_utf8=$'360237246204'
$ printf "$UNICORN_utf8_printf_formatn"
ð¦Â
$ printf '%sn' "$UNICORN_utf8"
ð¦Â
$ shopt -s xpg_echo
$ echo "$UNICORN_utf8_echo"
ð¦Â
Above, only $UNICORN_utf8
contains a ð¦ character, encoded in UTF8. The other ones contain sequences of backslash and digits that are meant to be expanded by the respective tools.
The %b
format of the printf
utility also understands the same sequences as echo
. %b
was actually added so we can get rid of echo
which is impossible to use portably and reliably.
$ printf '%bn' "$UNICORN_utf8_echo"
ð¦Â
See also (in zsh
and bash
ó):
UNICORN_locale_encoding=$'U1f984'
Which gets you a Unicorn encoded in the locale's encoding, which would make it work even if the locale's encoding was not UTF-8 and also had that character (probably only GB18030, where ð¦ is encoded as $'2256033066'
and where $'360237246204'
would be the encoding of é¦Âî©
(NCJK UNIFIED IDEOGRAPH-9983N<private use area-E6E9>
)).
Some printf
implementations (including GNU printf
and the printf
builtin of zsh
, ksh93
and recent versions of bash
(4.2 or above)) also support those UXXXXXXXX
escape sequences in their format argument (or arguments to %b
except with ksh93); the GNU one needs 8 digits.
ù GNU coreutils echo
and busybox echo
support ooo
with -e
as an extension (not when POSIXLY_CORRECT
is in the environment for GNU echo
)
ò other option would be to use the non-standard -e
option, but then it wouldn't work when both the posix
and xpg_echo
options are enabled, like when bash
is in UNIX compliance mode.
ó ksh93 and mksh also support that syntax, but encode in UTF-8 regardless of the locale's encoding; in current (2018) versions of FreeBSD sh
, you need U0001f984
and it only works in UTF-8 locales.
edited Sep 6 at 12:16
answered Sep 6 at 10:59
Stéphane Chazelas
283k53521858
283k53521858
1
Most complete answer! Much appreciated, glad to see this!
â Marcus Linsner
Sep 6 at 11:11
add a comment |Â
1
Most complete answer! Much appreciated, glad to see this!
â Marcus Linsner
Sep 6 at 11:11
1
1
Most complete answer! Much appreciated, glad to see this!
â Marcus Linsner
Sep 6 at 11:11
Most complete answer! Much appreciated, glad to see this!
â Marcus Linsner
Sep 6 at 11:11
add a comment |Â
up vote
3
down vote
$ echo $'36023723020012'
ðÂÂÂ
(that's bash
's echo
, GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu))
Or you can use the echo
binary:
$ /usr/bin/echo -e "36023723020012"
ðÂÂÂ
How did I get it? I used maulinglawns's answer above to see the emoji's octal:
$ printf "U1F600n"
ðÂÂÂ
$ printf "U1F600n"|hexdump -b
0000000 360 237 230 200 012
0000005
hexdump
:-b, --one-byte-octal one-byte octal display
EDIT: If you wanted the unicorn emoji:
$ echo $'360237246204'
ð¦Â
$ `which echo` -e '360237246204'
ð¦Â
If you want some generic way of getting the octal in that format:
printf "U1F600n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
36023723020012
The output includes the n
as 12
. The ";echo" will add a newline at the end, it's useful for when trying it on command line, else the shell prompt will be shown right after the output.
thanks for that functionhexdump -b
:)
â intercoder
Sep 6 at 14:17
add a comment |Â
up vote
3
down vote
$ echo $'36023723020012'
ðÂÂÂ
(that's bash
's echo
, GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu))
Or you can use the echo
binary:
$ /usr/bin/echo -e "36023723020012"
ðÂÂÂ
How did I get it? I used maulinglawns's answer above to see the emoji's octal:
$ printf "U1F600n"
ðÂÂÂ
$ printf "U1F600n"|hexdump -b
0000000 360 237 230 200 012
0000005
hexdump
:-b, --one-byte-octal one-byte octal display
EDIT: If you wanted the unicorn emoji:
$ echo $'360237246204'
ð¦Â
$ `which echo` -e '360237246204'
ð¦Â
If you want some generic way of getting the octal in that format:
printf "U1F600n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
36023723020012
The output includes the n
as 12
. The ";echo" will add a newline at the end, it's useful for when trying it on command line, else the shell prompt will be shown right after the output.
thanks for that functionhexdump -b
:)
â intercoder
Sep 6 at 14:17
add a comment |Â
up vote
3
down vote
up vote
3
down vote
$ echo $'36023723020012'
ðÂÂÂ
(that's bash
's echo
, GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu))
Or you can use the echo
binary:
$ /usr/bin/echo -e "36023723020012"
ðÂÂÂ
How did I get it? I used maulinglawns's answer above to see the emoji's octal:
$ printf "U1F600n"
ðÂÂÂ
$ printf "U1F600n"|hexdump -b
0000000 360 237 230 200 012
0000005
hexdump
:-b, --one-byte-octal one-byte octal display
EDIT: If you wanted the unicorn emoji:
$ echo $'360237246204'
ð¦Â
$ `which echo` -e '360237246204'
ð¦Â
If you want some generic way of getting the octal in that format:
printf "U1F600n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
36023723020012
The output includes the n
as 12
. The ";echo" will add a newline at the end, it's useful for when trying it on command line, else the shell prompt will be shown right after the output.
$ echo $'36023723020012'
ðÂÂÂ
(that's bash
's echo
, GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu))
Or you can use the echo
binary:
$ /usr/bin/echo -e "36023723020012"
ðÂÂÂ
How did I get it? I used maulinglawns's answer above to see the emoji's octal:
$ printf "U1F600n"
ðÂÂÂ
$ printf "U1F600n"|hexdump -b
0000000 360 237 230 200 012
0000005
hexdump
:-b, --one-byte-octal one-byte octal display
EDIT: If you wanted the unicorn emoji:
$ echo $'360237246204'
ð¦Â
$ `which echo` -e '360237246204'
ð¦Â
If you want some generic way of getting the octal in that format:
printf "U1F600n"|hexdump -v -e '"\" 1/1 "%03o"' ; echo
36023723020012
The output includes the n
as 12
. The ";echo" will add a newline at the end, it's useful for when trying it on command line, else the shell prompt will be shown right after the output.
edited Sep 6 at 15:02
answered Sep 6 at 10:53
Marcus Linsner
10914
10914
thanks for that functionhexdump -b
:)
â intercoder
Sep 6 at 14:17
add a comment |Â
thanks for that functionhexdump -b
:)
â intercoder
Sep 6 at 14:17
thanks for that function
hexdump -b
:)â intercoder
Sep 6 at 14:17
thanks for that function
hexdump -b
:)â intercoder
Sep 6 at 14:17
add a comment |Â
intercoder is a new contributor. Be nice, and check out our Code of Conduct.
intercoder is a new contributor. Be nice, and check out our Code of Conduct.
intercoder is a new contributor. Be nice, and check out our Code of Conduct.
intercoder is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f467247%2fproblems-escaping-a-variable-when-using-echo%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
Welcome to this site! Any reason why you don't want to use
printf
? Also see this relevant question unix.stackexchange.com/questions/65803/â¦â Mr Shunz
Sep 6 at 9:51
2
This is a follow-on question to unix.stackexchange.com/questions/466961 .
â JdeBP
Sep 6 at 9:53
1
octet
and evenn
areprintf
syntax. what makes you expectecho
knos ho to interpret them?â Philippos
Sep 6 at 9:54
@Philippos thanks, I thought that
printf
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 hasecho "Ready to git-some and sync your local branches to the remote counterparts ?"
â intercoder
Sep 6 at 14:02
@JdeBP correct that is the follow up question to actually all my questions here. I'm trying to incorporate emojis into my script
â intercoder
Sep 6 at 14:16