Skip to main content
added 1 character in body
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

You can do this in a different way (since bash appears to ignore escaped backslashes around the u in "\u"):

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u$(printf "%0*x" 4 $HEX)"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

though of course, the script is still bash-specific. A few other comments:

  • most people would suggest using $( and )` and ) rather than back-tics.
  • bash's printf can print Unicode directly (no need for the echo).
  • the extra printf for UCODECHAR is redundant

Eliminating the redundancy:

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u${UCODENAME}"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

You can do this in a different way (since bash appears to ignore escaped backslashes around the u in "\u"):

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u$(printf "%0*x" 4 $HEX)"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

though of course, the script is still bash-specific. A few other comments:

  • most people would suggest using $( and )` rather than back-tics.
  • bash's printf can print Unicode directly (no need for the echo).
  • the extra printf for UCODECHAR is redundant

Eliminating the redundancy:

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u${UCODENAME}"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

You can do this in a different way (since bash appears to ignore escaped backslashes around the u in "\u"):

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u$(printf "%0*x" 4 $HEX)"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

though of course, the script is still bash-specific. A few other comments:

  • most people would suggest using $( and ) rather than back-tics.
  • bash's printf can print Unicode directly (no need for the echo).
  • the extra printf for UCODECHAR is redundant

Eliminating the redundancy:

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u${UCODENAME}"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done
clarify
Source Link
Thomas Dickey
  • 79.2k
  • 9
  • 189
  • 289

You can do this in a different way (since bash appears to ignore escaped backslashes around the u in "\u"):

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u$(printf "%0*x" 4 $HEX)"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

though of course, the script is still bash-specific. A few other comments:

  • most people would suggest using $( and )` rather than back-tics.
  • bash's printf can print Unicode directly (no need for the echo).
  • the extra printf for UCODECHAR is redundant

Eliminating the redundancy:

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u${UCODENAME}"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

You can do this in a different way (since bash appears to ignore escaped backslashes around the u in "\u"):

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u$(printf "%0*x" 4 $HEX)"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

though of course, the script is still bash-specific. A few other comments:

  • most people would suggest using $( and )` rather than back-tics.
  • bash's printf can print Unicode directly (no need for the echo).

You can do this in a different way (since bash appears to ignore escaped backslashes around the u in "\u"):

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u$(printf "%0*x" 4 $HEX)"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

though of course, the script is still bash-specific. A few other comments:

  • most people would suggest using $( and )` rather than back-tics.
  • bash's printf can print Unicode directly (no need for the echo).
  • the extra printf for UCODECHAR is redundant

Eliminating the redundancy:

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u${UCODENAME}"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done
Source Link
Thomas Dickey
  • 79.2k
  • 9
  • 189
  • 289

You can do this in a different way (since bash appears to ignore escaped backslashes around the u in "\u"):

#!/bin/bash

X=0

while [ $X -lt 65536 ]; do
    HEX=$(bc <<< "obase=16; $X")
    HEX="0x${HEX}"
    UCODENAME=$(printf "%0*x\n" 4 $HEX)
    UCODECHAR="\\u$(printf "%0*x" 4 $HEX)"
    echo -e "Unicode ${UCODENAME} = ${UCODECHAR}"
    X=$((X + 1))
done

though of course, the script is still bash-specific. A few other comments:

  • most people would suggest using $( and )` rather than back-tics.
  • bash's printf can print Unicode directly (no need for the echo).