I'm writing a custom startup command for gnome-terminal, and my intention is to display a welcome message every time I launch it.
The message displays correctly, I coded it in order to make the letters appear one by one in a time rate of 0.09s:
echo -n "W" sleep 0.09 echo -n "e" sleep 0.09 echo -n "l" sleep 0.09 echo -n "c" sleep 0.09 echo -n "o" sleep 0.09 echo -n "m" sleep 0.09 echo -n "e" sleep 0.09
While testing it, I thought it would be quite comfortable to be able to stop the letters from appearing and start
su directly. I came up with the following solution:
su --command "read -n 1 -s key; if [[ "$key" == "g" ]]; then echo "Test Successful."; else echo "Test Failed."; fi;"
I have to use
su -c if I don't want bash to get angry and throw an
illegal action: read -n. This code snippet is for debugging purposes exclusively, as I wanted to test how does bash read the one-line command combination.
The main problem comes when I try to execute this code from the config file (the one where I write my custom command for startup). Bash returns:
No passwd entry for user 'Successful.; else echo Test' Welcome
Mysteriously, when I try the same command (without
su -c ) in the default profile it works perfectly, but if I try it with su -c, it doesn't.
Trying with other commands in the default profile, I typed
su -c "echo Hi" and worked fine. Why could be this happening? Do you have any idea?