soooo just found out i cound write and carry out functions and loops in a terminal window.... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

soooo just found out i cound write and carry out functions and loops in a terminal window....

was playing around in my terminal and messed around and tried out a function with parameters and got a response that i didnt expect, i wonder how far i can go with this

25th Jul 2017, 5:02 AM
Escobar
Escobar - avatar
13 Answers
+ 1
You're missing a "fi" ;)
30th Jul 2017, 8:22 AM
Bogdan Sass
Bogdan Sass - avatar
0
What language? And what do you mean by "terminal"? Python interpreter? Bash prompt? Windows command prompt?
25th Jul 2017, 6:27 AM
Bogdan Sass
Bogdan Sass - avatar
0
i guess it falls in tgat category of bash prompt, and the terminal is the one on my android device are you familiar with this terminal?? because mine seems to not have the "expr" cmd and i dont kno why
28th Jul 2017, 7:37 PM
Escobar
Escobar - avatar
0
the language is shell scripting hovever ive yet to root the device so many permissions on certain cmds and directories are prohibited' id like to root however im not sure if i can do it from the device alone and without a desktop pc
28th Jul 2017, 7:39 PM
Escobar
Escobar - avatar
0
What app are you using to access the terminal? I'm curious, because as far as I know most android devices don't come with such an app. In my case (using Terminal Emulator on an S8+), expr does work: dream2lte:/ $ expr 5 + 3 '*' 17 56 dream2lte:/ $
29th Jul 2017, 5:20 AM
Bogdan Sass
Bogdan Sass - avatar
0
its terminal emulator that im using as well but not with an S8 and i took a look through my system/bin and noticed the expr cmd isnt even stored on my device, thats wierd...
29th Jul 2017, 5:38 AM
Escobar
Escobar - avatar
0
In my case, expr is symlinked to toybox: dream2lte:/system/bin $ which expr /system/bin/expr dream2lte:/system/bin $ ls -l expr lrwxr-xr-x 1 root shell 6 2017-05-19 16:40 expr -> toybox dream2lte:/system/bin $ toybox expr 5 + 3 8 dream2lte:/system/bin $ If you have toybox on your system, you can use that directly.
29th Jul 2017, 5:55 AM
Bogdan Sass
Bogdan Sass - avatar
0
i just found it on my gfs s8 im having trouble with this if then else statement, do you see where i went wrong?? #this code will find file and give info by prompt echo "enter the file you want to find:\c" read ans if [ -f $ans ] then echo "would you like to know if this file is writable?\c" read yesorno if [ -w $ans -a $yesorno= Y ] then echo "this file is writeable" else if [ $yesorno= N ] then echo "would you like to know is it readable" read yon if [ -r $ans -a $yon= Y ] then echo "this file is readable" if [ $yon= N ] then echo "pleasure doing business with you" fi else echo "bro there aint no file here by that name" fi shell starts off understanding but gets lost at one of my if statements 1|u0_a118@e1q:/storage/emulated/0/practice2 $ sh atem3.sh enter the file you want to find:mathp.sh atem3.sh[13]: syntax error: 'if' unmatched
30th Jul 2017, 5:28 AM
Escobar
Escobar - avatar
0
sigh...(head drops), whem its things that simple, i just feel so dumb....and i hate that i had that thought and second guessed myself without even giving it a try...thanks...
30th Jul 2017, 8:48 AM
Escobar
Escobar - avatar
0
If I had a nickel for every time that happened to me... :)) Actually, it still happens - sometimes I miss a "fi", other times the spaces around if's brackets get me... :) Bottom line is "don't worry - it happens to everyone!" :)) [ Edited to add - that's why I strongly insist that all my students properly indent their code. It makes catching such mistakes so much easier! ]
30th Jul 2017, 9:23 AM
Bogdan Sass
Bogdan Sass - avatar
0
lol, thanks, the indentation trick does help alot
30th Jul 2017, 8:02 PM
Escobar
Escobar - avatar
0
hey, im having all the trouble in the world using "am start" cmd have you had much luck with it, i cant embedd it in my script of i cant use it successfully but i always get a prompt that im the wrong user instead of incorrect syntax, will i need su permissions to use that command???
1st Aug 2017, 4:12 AM
Escobar
Escobar - avatar
0
I managed to get it to work by adding --user 0 to the command ( as per the thread here: https://stackoverflow.com/questions/18179159/permission-denial-startactivity-asks-to-run-as-user-2-but-is-calling-from-user ) (Edited to add: that's a double dash in front of "user"!) And next time you encounter an error, please try to provide the actual error message - in this case, "Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL". It would have saved me a lot of time spent experimenting with the commands on a phone keyboard :p
1st Aug 2017, 7:00 PM
Bogdan Sass
Bogdan Sass - avatar