Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adb shell input text does not take & ampersand character

Tags:

android

adb

When I do enter some text with & character then my complete text is not entered on the device.

D:\Apps\Android-SDK\tools>adb shell input text hello&hello
'hello' is not recognized as an internal or external command,
operable program or batch file.

It entered only hello. but the other & and hello characters are not entered.

How can I enter the & character?

like image 361
a.t.obulreddy Avatar asked Sep 11 '14 15:09

a.t.obulreddy


2 Answers

You need to encapsulate your string in quotes and escape your ampersand "hello\&hello"

like image 80
Stephen Avatar answered Dec 23 '22 10:12

Stephen


( ) < > | ; & * \ ~ " ' and space all need escaping. Space can be replaced with %s.

I have written an android command line tool to do this call inputer.
A function from my code is here (uses regex):

//e.g. convert string "hello world\n" to string "hello%sworld\n"
    char * convert(char * trans_string)
    {
        char *s0 = replace(trans_string, '\\', "\\\\");
        free(trans_string);
        char *s = replace(s0, '%', "\\\%");
        free(s0);
        char *s1 = replace(s, ' ', "%s");//special case for SPACE
        free(s);
        char *s2 = replace(s1, '\"', "\\\"");
        free(s1);
        char *s3 = replace(s2, '\'', "\\\'");
        free(s2);
        char *s4 = replace(s3, '\(', "\\\(");
        free(s3);
        char *s5 = replace(s4, '\)', "\\\)");
        free(s4);
        char *s6 = replace(s5, '\&', "\\\&");
        free(s5);
        char *s7 = replace(s6, '\<', "\\\<");
        free(s6);
        char *s8 = replace(s7, '\>', "\\\>");
        free(s7);
        char *s9 = replace(s8, '\;', "\\\;");
        free(s8);
        char *s10 = replace(s9, '\*', "\\\*");
        free(s9);
        char *s11 = replace(s10, '\|', "\\\|");
        free(s10);
        char *s12 = replace(s11, '\~', "\\\~");
        //this if un-escaped gives current directory !
        free(s11);
        char *s13 = replace(s12, '\¬', "\\\¬");
        free(s12);
        char *s14 = replace(s13, '\`', "\\\`");
        free(s13);
    //  char *s15 = replace(s14, '\¦', "\\\¦");
    //  free(s14);
        return s14;
}
like image 39
Jon Goodwin Avatar answered Dec 23 '22 09:12

Jon Goodwin