By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,419 Members | 1,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,419 IT Pros & Developers. It's quick & easy.

(patch for Bash) try-block and exception

P: n/a
(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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.