# Scripting



## benwalburn (Aug 25, 2011)

I've been working on writing a bash script that will display the files in a directory of the sdcard. Each file in that directory contains a framework-res.apk that I want to flash. I got one working for my computer using simulated directories but when I try it on my android, I get a syntax error saying "bad for loop variable" on line 56 (line 56 reads "done")
I reverted back to an earlier version that has a working menu but not the ability to see my theme directory or flash themes. My current goal is getting the correct syntax to push from the directory to /sytem/framework
I'm an idiot, I had my framework-res.apk within an extra directory. Corrected and the theme appears to flash perfectly. Now I need to make the theme chooser work as I described above.

I would appreciate any help with this. I posted the last working version of my code at http://pastebin.com/Ppy38gCa
Now I need to know how to make it display the folders within /prevail/themes, assign them a number that when chosen replaces a directory to flash the framework. It should do something like this:

Choose theme:
1. red
2. blue
3. green
>

(and the script should say "cp /mnt/sdcard/prevail/theme/[chosen directory]/framework-res.apk /system/framework")

Another update:
I linked my second option to another script (http://pastebin.com/RTVrLWjY) 
*Now I need to find out how to list all folders within another directory and assign them as a variable within my script.*


----------



## yarly (Jun 22, 2011)

This might sound odd, but make sure it's actually executing a bash shell? Try putting a space in between the #! on #!/bin/bash so it's like #! /bin/bash. Also is that where bash is on your phone or is it under /xbin/bash?

Also, try putting the following at the top to double check it's really bash:


```
<br />
set -vx<br />
echo "Random = $RANDOM"   # Will only work on BASH<br />
echo \$BASH_VERSINFO[0] = ${BASH_VERSINFO[0]} #Should only work in BASH only<br />
```


----------



## benwalburn (Aug 25, 2011)

yarly said:


> This might sound odd, but make sure it's actually executing a bash shell? Try putting a space in between the #! on #!/bin/bash so it's like #! /bin/bash. Also is that where bash is on your phone or is it under /xbin/bash?
> 
> Also, try putting the following at the top to double check it's really bash:
> 
> ...


Once again, I'm an idiot. I automatically assumed my rom had bash by default. It didn't. I installed it and now have something new to deal with.

The script tells me that there's one directory in /mnt/sdcard/prevail/theme. So I assume I wrote the script wrong. Can anyone correct that? It's the second script on the OP


----------

