Results 1 to 3 of 3

Thread: Unicode in bash shell ?

  1. #1
    Join Date
    Dec 2007
    Location
    India
    Beans
    176
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Question Unicode in bash shell ?

    Hai Friends,

    How to print Unicode Character in a terminal Using Bash Script ?

    Thanks
    असतो मा सद्गमय तमसो मा ज्योतिर्गमय मृत्योर् मा अमृतं गमय

  2. #2
    Join Date
    Dec 2007
    Beans
    222

    Re: Unicode in bash shell ?

    Code:
    man bash
    370g

    \nnn the eight-bit character whose value is the octal value nnn (one to three digits)
    \xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
    An example:

    % (percent symbol) U+0025, Oct 045

    Code:
    echo $'\x25'
    echo $'\045'
    awk '{if($4=/mAh/)rc=$3}END{print((rc*100)/4800)"\x25"}' /proc/acpi/battery/BAT1/state
    awk '{if($4=/mAh/)rc=$3}END{print((rc*100)/4800)"\045"}' /proc/acpi/battery/BAT1/state
    awk '{if($4=/mAh/)rc=$3}END{print((rc*100)/4800)"%"}' /proc/acpi/battery/BAT1/state
    You can type symbols right in terminal by pressing Alt-<key> or Alt-Shift-<key>:

    -- Alt-Shift-3
    € -- Alt-Shift-4
    -- Alt-Shift-5
    -- Alt-Shift--
    -- Alt-1
    -- Alt-w
    -- Alt-Shift-w
    -- Alt-9
    -- Alt-2
    -- Alt-3
    -- Alt-Shift-,
    -- Alt-=
    -- Alt-Shift-.
    -- Alt-;
    -- Alt-Shift-=
    -- Alt-'
    -- Alt-.
    -- Alt-Shift-0
    -- Alt-0
    -- Alt-Shift-1
    -- Alt-Shift-/

    Note: This is not a complete list.
    Last edited by pauper; July 30th, 2008 at 11:40 AM. Reason: A few more examples.
    Help yourself | [Hints] Disassemble your laptop

    "Si peccasse negamus, fallimur,
    Et nulla est in nobis veritas--"

  3. #3
    Join Date
    Dec 2007
    Beans
    222

    Re: Unicode in bash shell ?

    Some clarification is due.

    1) bash shell
    • Only these 94 ASCII characters can be represented with "\nnn" or "\xHH":

      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijkl
      mnopqrstuvwxyz{|}~
      # [033-126]

      The following special characters you type via Alt-<key> and
      Alt-Shift-<key> but not their hexadecimal or octal numbers.


      # [161-255]
    • You can use <Compose key><key><key>, i.e. <Compose key><+><-> -- .

      Code:
      less /usr/share/X11/locale/en_US.UTF-8/Compose

    Note: Keep in mind though, if you are going to redirect output from bash script
    to some GUI environment, you might need to use escapes ("\nnn" or "\xHH") for
    # [161-255] characters.

    2) gedit
    • Use <Ctrl><Shift><u><Unicode number><Enter>
    • <Compose key><key><key>.

    A lot more characters are supported.

    3) Vim (Insert mode)
    • Press Ctrl-v {char} {value};
      Code:
       +---------------+--------------+----------------+------------------------+
       | first char    |  mode        | max nr of chars|  max value             | 
       +---------------+--------------+----------------+------------------------+
       | (none)        |  decimal     |      3         |  255                   |
       | o or O        |  octal       |      3         |  377 (255)             |
       | x or X        |  hexadecimal |      2         |  ff  (255)             |
       | u             |  hexadecimal |      4         |  ffff (65535)          |
       | U             |  hexadecimal |      8         |  7fffffff (2147483647) |
       +---------------+--------------+----------------+------------------------+
    • Press Ctrl-k {char1} {char2}, where {char1} is a special key;
      Code:
       +-------------------+--------+------------------------------------+
       |  char name        |  char1 | meaning                            |
       +-------------------+--------+------------------------------------+
       |  Exclamation mark |  !     | Grave                              |
       |  Apostrophe       |  '     | Acute accent                       |
       |  Greater-Than sign|  >     | Circumflex accent                  |
       |  Question Mark    |  ?     | tilde                              |
       |  Hyphen-Minus     |  -     | Macron                             |
       |  Left parenthesis |  (     | Breve                              |
       |  Full Stop        |  .     | Dot Above                          |
       |  Colon            |  :     | Diaeresis                          |
       |  Comma            |  ,     | Cedilla                            |
       |  Underline        |  _     | Underline                          |
       |  Solidus          |  /     | Stroke                             |
       |  Quotation mark   |  "     | Double acute accent                |
       |  Semicolon        |  ;     | Ogonek                             |
       |  Less-Than sign   |  <     | Caron                              |
       |  Zero             |  0     | Ring above                         |
       |  Two              |  2     | Hook                               |
       |  Nine             |  9     | Horn                               |
       |                   |        |                                    |
       |  Equals           |  =     | Cyrillic                           |
       |  Asterisk         |  *     | Greek                              |
       |  Percent sign     |  %     | Greek/Cyrillic special             |
       |  Plus             |  +     | smalls: Arabic, capitals: Hebrew   |
       |  Three            |  3     | some Latin/Greek/Cyrillic letters  |
       |  Four             |  4     | Bopomofo                           |
       |  Five             |  5     | Hiragana                           |
       |  Six              |  6     | Katakana                           |
       +-------------------+--------+------------------------------------+
    • <Compose key><key><key>
    Last edited by pauper; July 30th, 2008 at 11:41 AM.
    Help yourself | [Hints] Disassemble your laptop

    "Si peccasse negamus, fallimur,
    Et nulla est in nobis veritas--"

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •