Introduction
Aaj hum ek aise technical topic par baat karne wale hain jo aapke AndLua+ projects ki capability ko ek alag level par le jayega – Shell Scripts (.sh files) ko run karna. Agar aap advanced automation, file operations, ya system-level tasks apne app me add karna chahte hai, toh yeh guide aapke liye hai.
Yeh post sirf educational purpose ke liye hai. Hume seekhna hai ki technology kaise kaam karti hai, taki hum usse acchi cheeze banane mein use kar sake.
Video Tutorial
Agar aap is tutorial ko video ki madat se samajhna chahte hai to maine eak video bana diya hai jisme maine sab kuch step by step bataya hai [embedded below]
Shell Scripts Kya Hote Hain?
Pehle yeh samajh lete hain ki hum kya karne ja rahe hain. .sh files ko Shell Scripts bhi kehte hain. Ye aise scripts hote hain jo Linux/Android system ko direct commands dete hain. Jaise:
- Files delete karna
- Folders create karna
- System information nikalna
- Permissions change karna
AndLua+ normally Lua code chalta hai, lekin hum kuch tricks use karke isse shell commands bhi run kara sakte hain. Yeh thoda advanced hai, lekin main aapko aasaan steps mein samjhaunga.
Step 1: Apni .sh File Taiyar Karna
Sabse pehle, aapko ek shell script file banani hai ya use karni hai.
- Koi Bhi Text Editor Use Kare: Aap MT Manager, Simple Text Editor, ya apne phone ke notes app ka use kar sakte hain.
- Simple Command Daale: Shuruat mein koi aasaan command daalen. Jaise:
#!/system/bin/shecho "Hello from Shell Script!"Ya phir koi practical example:#!/system/bin/shrm -f /sdcard/MyFolder/*.png(Yeh commandMyFolderki saari PNG files delete kar dega) - File Save Kare: Is file ko
.shextension ke saath save karein. Jaise:demo.sh - Ek Alag Folder Banaye: Apne project ke andar ek naya folder banayein (jaise
sh_folder) aur usme yeh file save karein.
Note: Hamesha yaad rakhein – powerful commands careful use karein. Galat command aapka data delete kar sakti hai.
Step 2: AndLua+ Project Mein Code Add Karna
Ab humein apne AndLua+ project ko modify karna hoga taki woh shell scripts ko handle kar sake.
- AndLua+ Project Open: Apna project open kare jisme aap yeh feature add karna chahte hain.
- Code Copy Kare: Aapko do parts copy karne honge:
- Import Section: Jo code
importse shuru hota hai, use apnemain.luafile ke top mein paste karein (already existing imports ke neeche). - Function Section: Jo code
functionse shuru hota hai, use apne existing functions ke section mein paste karein.
- Import Section: Jo code
- Function Ka Naam Change Kare: Default function name ko apne project ke hisaab se change kare. Jaise:
function my_script(id)-- yaha code aayegaend
Step 3: Folder aur File Ka Naam Set Karna
Ab hume code ko batana hoga ki script kaha hai aur uska naam kya hai.
- Variable Dhundo: Code mein kahi aapko yeh lines milegi:
folder_name = "sh_folder" shell_file_name = "demo.sh" - Apne Hisaab Se Change Kare:
folder_nameme wo folder ka naam daale jaha aapne.shfile rakhi hai.shell_file_nameme apni script file ka naam daale.
Example: Agar aapka folder scripts hai aur file cleanup.sh hai, toh aise daale:
folder_name = "scripts"
shell_file_name = "cleanup.sh"
Step 4: Project Ko Build Aur Test Karna
Yeh sabse important step hai. Shell scripts properly tab hi chalengi jab aap project ko build karke asli app banayenge.
- Editor Mein Direct Run Naa Karein: AndLua+ editor mein directly run karne se shell script kaam nahi karegi. Yeh limitation Android security ki wajah se hai.
- Build APK Kare: Project ko complete build karein aur ek APK file generate karein.
- App Install Kare: Banayi hui APK ko install karein.
- Test Kare: Ab app open karke us feature ko test karein jo aapne shell script se jodi thi.
Testing Tips:
- Pehle simple commands se test kare (jaise
echo). - Phir gradually advanced commands try kare.
- Hamesha test device pe try karein, personal device pe nahi.
Practical Example
Maine apne test project mein yeh kiya:
- Script Banayi:
clean_images.shnaam ki file banayi jisme yeh command thi:#!/system/bin/sh(Yeh
rm -f /sdcard/TestAssets/*.pngTestAssetsfolder ki saari PNG pictures delete karti hai) - Function Link Kiya: Ek button banaya jiska ID
btn_cleantha. Usse iss function se link kiya. - APK Banayi: Project ko build karke app banayi.
- Result: Jab maine app mein button click kiya:
- Ek toast message dikha: “Done!”
TestAssetsfolder ki saari PNG files delete ho gayi.
Yeh confirm karne ke liye ki script actually run hui, maine MT Manager se folder check kiya.
Kuch Common Problems aur Solutions
Problem 1: Script Run Nahi Hoti
- Solution: Check kare ki aapne APK build ki hai ya nahi. Editor mein direct run nahi hogi.
Problem 2: Permission Denied Error
- Solution: Ensure kare ki aapki script file mein execute permission hai. MT Manager mein file properties check karein.
Problem 3: File/Folder Not Found
- Solution: Double-check kare ki folder aur file ke names exactly match kar rahe hain. Capital/small letters matter karte hai.
Problem 4: Command Not Working
- Solution: Pehle terminal mein directly command try kare taaki pata chal sake ki command sahi hai ya nahi.
Safety Tips aur Best Practices
- Backup Lena Na Bhule: Kisi bhi dangerous command (jaise
rm -f) ko use karne se pehle apna data backup kar lein. - Test Karne Ke Liye Alag Device Use Kare: Agar possible ho toh ek test device use kare taki aapka personal data safe rahe.
- Simple Commands Se Shuruat Kare: Pehle “Hello World” jaise simple commands try kare, phir gradually advanced tasks kare.
- Comments Use Kare: Apne code mein comments daalte rahe taaki baad mein samajh me aaye ki kya ho raha hai.
Aage Ke Liye Ideas
Jab aap shell scripts run karna seekh jaate hai, toh aap yeh kar sakte hain:
- Auto Backup System: Apne app ka data automatically backup karne wala script.
- Cleanup Tool: Temporary files automatically delete karne wala tool.
- System Info Tool: Device ki information nikalne wala app.
- Custom Automation: Apne hisaab ke repetitive tasks automate karna.
Conclusion
Doston, aaj humne seekha ki kaise hum AndLua+ ki limitation ko overcome karke shell scripts run kar sakte hai. Yeh thoda technical hai, leikin bahut powerful bhi hai.
Humne cover kiya:
- Shell scripts kya hote hai
- .sh file kaise banate hai
- AndLua+ project me code kaise add karte hai
- Build process ka importance
- Testing aur safety tips
Yaad rakhe – with great power comes great responsibility. Shell commands bahut powerful hote hain, isliye unhe carefully use karein.
Agar aapko koi step samajh nahi aaya ya koi problem aa rahi hai, toh niche comment me zaroor puche. Mai help karne ki koshish karunga.
– DevelopEye Tutorials