473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

(patch for Bash) try-block and exception

(crossposted to comp.lang.python, because this may be of interest to
them.)

Python has try-block, within which you can raise exception. Once it's
raised, execution breaks out of the try-block and is caught at the end
of try-block.

Now, Bash has similiar feature. I've added try-block and 'raise'
builtin into Bash-3.0. Typical usage would go something like
try
echo a
raise
echo b
done
or
try
echo a
raise 2
echo b
done in
0) echo okey ;;
1) echo raised 1 ;;
2) echo raised 2 ;;
*) echo really bad ;;
esac

The exception is positive integer and is raised by 'raise' builtin, just
like 'break' for the for/while/until loops. And, it can be caught by
using optional case-like statement.

Ref:
http://freshmeat.net/projects/bashdiff/
help try
help raise

--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Toronto, Ontario, Canada
Jul 18 '05 #1
6 3368
In <comp.unix.shell> William Park <op**********@yahoo.ca> wrote:
(crossposted to comp.lang.python, because this may be of interest to
them.)

Python has try-block, within which you can raise exception. Once it's
raised, execution breaks out of the try-block and is caught at the end
of try-block.

Now, Bash has similiar feature. I've added try-block and 'raise'
builtin into Bash-3.0. Typical usage would go something like
try
echo a
raise
echo b
done
or
try
echo a
raise 2
echo b
done in
0) echo okey ;;
1) echo raised 1 ;;
2) echo raised 2 ;;
*) echo really bad ;;
esac
Typo... I pasted an old example. No globbing or any shell expansion is
done.
try
echo a
raise 2
echo b
done in
0) echo okey ;;
1) echo raised 1 ;;
2) echo raised 2 ;;
esac

The exception is positive integer and is raised by 'raise' builtin, just
like 'break' for the for/while/until loops. And, it can be caught by
using optional case-like statement.

Ref:
http://freshmeat.net/projects/bashdiff/
help try
help raise


--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Toronto, Ontario, Canada
Jul 18 '05 #2
William Park <op**********@yahoo.ca> writes:
Ref:
http://freshmeat.net/projects/bashdiff/
help try
help raise


This link doesn't appear to lead to a `download' option..
Jul 18 '05 #3
In <comp.lang.python> Harry Putnam <re****@newsguy.com> wrote:
William Park <op**********@yahoo.ca> writes:
Ref:
http://freshmeat.net/projects/bashdiff/
help try
help raise


This link doesn't appear to lead to a `download' option..


It's two step dance.
first, http://freshmeat.net/projects/bashdiff/
then, http://home.eol.ca/~parkw/index.html#bash (homepage)
then, http://home.eol.ca/~parkw/bash.diff

Next feature I'll tackle is list comprehension. :-)

--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Toronto, Ontario, Canada
Jul 18 '05 #4
In article <2n************@uni-berlin.de>,
William Park <op**********@yahoo.ca> wrote:
....
Next feature I'll tackle is list comprehension. :-)


Are you saying that you don't understand how lists work?
If so, post an item here - I'm sure people will be more than willing to help.

Jul 18 '05 #5
William Park wrote:
try
echo a
raise 2
echo b
done in
0) echo okey ;;
1) echo raised 1 ;;
2) echo raised 2 ;;
*) echo really bad ;;
esac


try...done...esac? What a delightfully eclectic combination
of syntax. :-)

Why doesn't it end with 'yrt'?

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
Jul 18 '05 #6
In <comp.unix.shell> Greg Ewing <gr**@cosc.canterbury.ac.nz> wrote:
William Park wrote:
try
echo a
raise 2
echo b
done in
0) echo okey ;;
1) echo raised 1 ;;
2) echo raised 2 ;;
*) echo really bad ;;
esac


try...done...esac? What a delightfully eclectic combination
of syntax. :-)

Why doesn't it end with 'yrt'?


'try-done' was chosen because it resembles while-loop where you would
break out of; and, '-in-esac' was chosen because it resembles case
statement. Also, I didn't want to introduce too many new keywords.

--
William Park, Open Geometry Consulting, <op**********@yahoo.ca>
Toronto, Ontario, Canada
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Bowling | last post by:
I have a java (2.0) program with the following lines: String cmdArray1 = {"lp", "-d", "hp4m", "MyFile"}; System.out.println(Runtime.getRuntime().exec(cmdArray1)); It compliles properly, but...
2
by: Eric Woudenberg | last post by:
I just installed a Python 2.3.4 Windows binary on a friend's WinXP machine (because the latest Cygwin-provided Python 2.3 build leaves out the winsound module for some reason). When I try and...
0
by: William Park | last post by:
1. Here is shell version of Python filter() for array. Essentially, you apply a command on each array element, and extract only those elements which it returns success (0). This is specialized...
4
by: Tom Purl | last post by:
I just wrote a Python script that is going to be called from bash script. If the Python script fails, I want the bash script to also stop running. Unfortunately, I can't seem to get that to work. ...
1
by: Stelios Xanthakis | last post by:
Hi all. Basically, I'd like to use python as my system shell. It's not suitable for a general purpose shell but since it is very programmable it can eventually do whatever bash does and even...
3
by: William Park | last post by:
I'm very excited to announce shell interface to GTK+2 (2.6.1) for Bash. It read XML syntax describing the widget layout, and returns user selection as shell variable or runs shell command as...
3
by: Joe | last post by:
Back in March I submitted a patch for cgi.py to sourceforge to fix a problem with the handling of an invalid REQUEST_METHOD. I thought I followed all the steps to properly submit the bug and...
3
by: Ben | last post by:
Hi there, We have a asp.net application working fine till a patch is applied to the machine. Now it encounter error 404 page not found, although the page is there. Has anyone come across this...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 404 open ( +2) / 3376 closed (+16) / 3780 total (+18) Bugs : 860 open ( -1) / 6131 closed (+17) / 6991 total (+16) RFE : 229 open...
4
by: melmack3 | last post by:
Hello My PHP script executes many bash/cmd commands. Functions like "exec()" or "system()" cause that new bash/cmd session is started, the command is executed and the session is closed....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.