How to use catch, try and final in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use catch, try and final in bash script
# 1  
Old 04-15-2009
How to use catch, try and final in bash script

Hi Everyone,

How to use catch, try and final in bash script?
what is (SQLException e) and (IOException e), who to conver this 2 function to bash script?

Thank you
# 2  
Old 04-16-2009
Quote:
Originally Posted by ryanW
Hi Everyone,

How to use catch, try and final in bash script?
You don't. BASH is not a OO language implementing any features remotely like that.
# 3  
Old 04-16-2009
is it posibble for me to the tranditional logical? coz i just need the logical.. so that i make by my own function instead of OO function...
# 4  
Old 04-16-2009
What do you mean by "traditional logic"? Shell scripts work pretty much like any functional language, a command can either work OK or fail. If the coder has been nice it will give you some information on why it failed. $? is the variable set to the return code of a program, 0 means "good", anything else usually is bad.

Exceptions are done by
  1. Knowing which program you called last (sed probably won't produce and SQL error) and
  2. hoping that the coder used different return codes for different errors, instead of just "good" and "bad"
# 5  
Old 04-16-2009
Thank you pludi and Corona688...

Regarding "tranditional logic, means normal logical... like if else...

I think shell script can do the OO function, just wan to know how its works for the (SQLException e) and (IOException e).

thankx...
# 6  
Old 04-16-2009
Quote:
Originally Posted by ryanW
I think shell script can do the OO function, just wan to know how its works for the (SQLException e) and (IOException e).
thankx...
no OO support for shell scripts. If you want OO, use a programming language like Python (Java, Ruby, even Perl). you can then use try,catch eg, Python
Code:
import os
try :
   os.rename(oldfile,newfile) #try to rename file
except Exception,e:
   print e #print error message
else:
   # do something if pass

# 7  
Old 04-16-2009
Well, if you're really really determined, very very frustration resistant, and have a whole lot of time on your hand, it might be possible to simulate OO in shell scripts.

And again, there are no exceptions in shell scripts, only "good" or "bad" exits
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

How to catch errors in a shell script ( multiple commands )?

Hi I have a shell script like that Main() { DAY=$(date +"%d-%m-%Y") TIME=$(date +"%T") Command 1 Command 2 ... Command n } I would like to catch errors from all commands in Main() and write these errors into a file , something likes this: Main if < error > then echo... (3 Replies)
Discussion started by: bobochacha29
3 Replies

3. Shell Programming and Scripting

How to catch sql error in script?

Hi Gurus, I have a script which send sql query to oracle db and return value to my script. dummy code like below: sqlplus -s user/${PASSWD}@${ORACLE_SID} @${DIR}/query.sql > outputfile using above code, when query has error, it send error to same out put file and exit code is 0, is... (6 Replies)
Discussion started by: ken6503
6 Replies

4. Shell Programming and Scripting

Addition to Bash shell script that emails final output as attachement?

Greetings. I have a nice bash shell script that runs a multi-step analysis well. I already have the SGE options set up to email me the progress of the run (started, completed, aborted), but a final step would be to code the shell script to email the final output (a .txt file) to the same email... (6 Replies)
Discussion started by: Twinklefingers
6 Replies

5. Shell Programming and Scripting

Shell script to catch PL/SQL return values

I tried searching the forum for similar posts but its closed now. Would appreciate any help on this. I am trying to capture return value from a select query into a variable. DB is Oracle I am able to spool it to a file but I donot intend to use it. Here is my script that does not work ;) I... (27 Replies)
Discussion started by: monie2717
27 Replies

6. Shell Programming and Scripting

How to catch ENTER key inside the shell script?

Hi, I have a script in which i have to ask user to press the ENTER key to proceed further. can you please help me how can i achive this in my scripting? echo "All the executables builded Successfully " echo " Press Enter to Go Back to the Main Menu" ... (2 Replies)
Discussion started by: plaban.rout
2 Replies

7. Shell Programming and Scripting

Shell script to catch PL/SQL return values

Hello, I need some help from the experts on PL/SQL and Shell scripting. I need a shell script that runs a PL/SQL procedure and gets the values returned from the PL/SQL procedure into the shell variables. The PL/SQL procedure returns multiple values. I was able to assign a single return value... (1 Reply)
Discussion started by: Veera_Raghav
1 Replies
Login or Register to Ask a Question