Same echo command which has control characters showing different output

70 views Asked by At

If I run echo -en "aap\0icon\x1f${icon}\n" like:

#!/usr/bin/env bash

array="Alacritty vscodium firefox-esr io.github.cboxdoerfer.FSearch folder"

for icon in ${array}; do
    echo -en "aap\0icon\x1f${icon}\n"
    echo -en "aap\0icon\x1f${icon}\n" | head -1 | od -c
done

The output of the command is:

$ ./test
aapiconAlacritty
0000000   a   a   p  \0   i   c   o   n 037   A   l   a   c   r   i   t
0000020   t   y  \n
0000023
aapiconvscodium
0000000   a   a   p  \0   i   c   o   n 037   v   s   c   o   d   i   u
0000020   m  \n
0000022
aapiconfirefox-esr
0000000   a   a   p  \0   i   c   o   n 037   f   i   r   e   f   o   x
0000020   -   e   s   r  \n
0000025
aapiconio.github.cboxdoerfer.FSearch
0000000   a   a   p  \0   i   c   o   n 037   i   o   .   g   i   t   h
0000020   u   b   .   c   b   o   x   d   o   e   r   f   e   r   .   F
0000040   S   e   a   r   c   h  \n
0000047
aapiconfolder
0000000   a   a   p  \0   i   c   o   n 037   f   o   l   d   e   r  \n
0000020

However, If I run echo -en "aap\0icon\x1f${icon}\n" like:

#!/usr/bin/env bash

json=$(dbus-send --print-reply=literal --session --dest=org.gnome.Shell /org/gnome/Shell/Extensions/GnomeUtilsWorkspaces org.gnome.Shell.Extensions.GnomeUtilsWorkspaces.GetWorkspaces)

workspace_names=$(echo $json | jq -c -r .workspace_names[])

for w in ${workspace_names}; do

all_normal_windows_of_nth_workspaces=$(echo $json | jq ".all_normal_windows_of_workspaces .$w" | jq -c '.[]' )

    for item in ${all_normal_windows_of_nth_workspaces}; do
        icon=$(dbus-send --print-reply=literal --session --dest=org.gnome.Shell /org/gnome/Shell/Extensions/GnomeUtilsWindows org.gnome.Shell.Extensions.GnomeUtilsWindows.GetIconFromWinID uint32:$item)
        echo -en "aap\0icon\x1f${icon}\n"
        echo -en "aap\0icon\x1f${icon}\n" | head -1 | od -c
    done
done

The output is like:

./test
aapicon   firefox-esr
0000000   a   a   p  \0   i   c   o   n 037               f   i   r   e
0000020   f   o   x   -   e   s   r  \n
0000030
aapicon   Alacritty
0000000   a   a   p  \0   i   c   o   n 037               A   l   a   c
0000020   r   i   t   t   y  \n
0000026
aapicon   firefox-esr
0000000   a   a   p  \0   i   c   o   n 037               f   i   r   e
0000020   f   o   x   -   e   s   r  \n
0000030
aapicon   firefox-esr
0000000   a   a   p  \0   i   c   o   n 037               f   i   r   e
0000020   f   o   x   -   e   s   r  \n
0000030
aapicon   vscodium
0000000   a   a   p  \0   i   c   o   n 037               v   s   c   o
0000020   d   i   u   m  \n
0000025

As a result I am unable to render the icons in rofi using ./test | rofi -dmenu or, rofi -show gn -modi "gn:./test".

One sample for rofi script can be found in https://github.com/davatorium/rofi/blob/next/Examples/test_script_mode.sh

Documentation also says that we need to render icon using echo -en "aap\0icon\x1ffolder\n".

I do not understand control characters well. Why does it work differently here. How can I have same output as first example, in the second code?

P.S. This is not necessary but if you want to know what is this script and how does it work then please check https://github.com/davatorium/rofi/discussions/1871

0

There are 0 answers