If statements/general help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers If statements/general help
# 1  
Old 10-31-2010
If statements/general help

Dear Unix community over the last couple of days I have been working on learning Unix scripting on iOS using terminal on a jail-broken device...
I am having trouble with if statements and giving the user a y or n choice that do different things when entered. The following is my code so far... Please tell me if you would like further explaining on what anything means or what i think it should do.
Thanks in advance,

Code:
#!/bin/bash
# iOS-Ad-Remover
# Marshall Ford @ marshallbford@ gmail.com
# This project is hosted @ http://ios-ad-
# remover.sourceforge.net
# Under the GNU GPL open source license
clear
date
echo
if [ `id -u` != 0 ]; then echo "You need to be root to run this script."; exit 0;
echo
fi
echo
echo "Welcome to iOS-Ad-remover Beta 0.1"
sleep 2
echo
echo "This script is similar to Adblock
in that it will remove ads from most apps,
some websites, and in Cydia."
sleep 1
echo
echo "You will need to meet the following
requirements..."
sleep 3
echo
echo "1. iFile installed and up to date"
sleep 3
echo
echo "2. The modified (hosts) file
that came with this script must located 
@ /var/mobile/Media/Downloads"
sleep 3
echo
echo "3. This script must be located
@ /var/mobile"
sleep 3
echo
echo "Have you completed the requirements
and still want to continue?"
echo
echo "y or n?"
sleep 1
read answer
# if [ "$answer" == 'y' ]; then
 echo "Backing-up"
 cd ..
 cd ..
 cd var/mobile/Media/Downloads
 mkdir backup
 cd ..
 cd ..
 cd ..
 cd ..
 cd etc
 cp fhosts /var/mobile/Media/Downloads/backup
 cd ..
 cd ..
 cd ..
 cd ..
 cd ..
 cd etc
 rm fhosts
fi
# if [ "$answer" == 'n' ]; then
 echo "Ad removal stopped by user."
 sleep 2
 echo "Good Bye"
 sleep 3
#end script

# 2  
Old 10-31-2010
It would be nice to know what it is doing that you don't expect/want.

The sleep calls are annoying (imho) and the one straight ahead of the read seems pointless.

If I uncomment the if statement, it parses and skips all of the cd'ing if I answer n, so Im not sure what your experience is, but it seems like the conditionals are OK; at least on my quick test.
# 3  
Old 11-01-2010
Well i just want to know if I was starting and stopping the if statements because on the iphone if i choose "y" then it will perform y and then "n", its like it doesn't no where the statements start and end. Anyway.... I need to know how to tell it to perform certain actions when the user clicks "y" and different actions when the user clicks "n"

---------- Post updated 11-01-10 at 06:27 AM ---------- Previous update was 10-31-10 at 07:49 PM ----------

One more note: I cannot find anywhere what shell the iphone iOS uses.
# 4  
Old 11-01-2010
Are you running the script exactly as you have it posted here? If so, you need to remove the hash (comment) symbols from in front of your if statements, and add a fi some where after the second if; probably immediately after the echo.

Unfortunately, I cannot answer the iOS question -- I'd assume bash, but we all know what happens when someone assumes.
# 5  
Old 11-01-2010
Thank you for finding the hash/comment mistake, however after adding a fi to the last line of code and removing hashes...
It spits out a line 72 unexacting end to script error.
Help!
# 6  
Old 11-02-2010
I'm not seeing what could be causing that from what is here. You could add the line
Code:
set -x

at the top of your script to trace what the interpreter is doing. That might give you a better clue as to where the error is.

If you need to, you can post the output generated with the set -x and someone here might spot the issue.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

General Framework For C

Hi guys. Is there any General Framework for C like other languages?:confused: for example .Net or ... . I googled but i didn't find anything useful. (5 Replies)
Discussion started by: majid.merkava
5 Replies

2. Shell Programming and Scripting

awk (?) help or just general script

I have two files (___ represents blanks) Foo1 1000 345 456 1001 876 908 1002 ___ 786 1003 643 908 1004 345 234 and Foo2 1000 345 1001 876 1002 111 1003 643 1004 345 (3 Replies)
Discussion started by: garethsays
3 Replies

3. Shell Programming and Scripting

General UNIX Query

Hi all, I am having putty in my system.But I dont have access to any UNIX Servers.Is there any default or common UNIX Server so that anyone can access and be familiar with UNIX and Shell scripting. I want to work and practice in UNIX..Thats why I am asking this question. Kindly give me... (2 Replies)
Discussion started by: dave_nithis
2 Replies

4. Shell Programming and Scripting

system general information

hi I am new to this forum. hope to get help from u all. how can i write these by using shell programming? 1. The name of the machine and the date/time at which the report was produced. 2. Licensing information such as the operating system revision level and license restrictions in terms of... (1 Reply)
Discussion started by: nokia1100
1 Replies

5. UNIX for Dummies Questions & Answers

general ledger balance.

My general ledger account did not balance to my posting journal. How can I change the general ledger account to balance with my posting journal without having to post a one sided ticket and have it go to my outage account? :confused: (1 Reply)
Discussion started by: Jenny
1 Replies

6. UNIX for Dummies Questions & Answers

General Query

Hi all My job is to bootup the servers (1 sun solaris 5.8, 3 sco (release 5) and 1 windows 2000), taking backup of the servers and shut down. Apart from this, there are nearly 150 users for our oracle9i database (forms 3 and d2k as front end). As for as oracle 9i is concerned my job is to... (0 Replies)
Discussion started by: raguramtgr
0 Replies

7. Shell Programming and Scripting

general question?

Perl, Python, and PHP are these languages easy to use? Are they command line or are they part of a GUI? (2 Replies)
Discussion started by: wmosley2
2 Replies

8. UNIX for Dummies Questions & Answers

General Question

Hi, I've been racking my brains trying to remember, but, whats the command to change the default shell? I'm currently always in the Korn shell and I want to start out in the Bash shell. I'm running a variant of BSD I guess in Mac OS X 10.2.2 and Mandrake. Thanks. ccindyderek:confused: (4 Replies)
Discussion started by: ccindyderek
4 Replies
Login or Register to Ask a Question