idea: statically-linked busy-bash
Dear All, Here's an idea that occurred to me. I'm not sure whether it's a great idea, or a really really stupid one, so please feel free to shoot it down. Anyway, there are an awful lot of shell scripts where a huge number of the coreutils get repeatedly called in separate processes. This call-overhead makes the scripts run noticeably slower. What I'm suggesting is to experimentally build a version of bash which has mv/cp/ls/stat/grep/ all built in. This would be a rather bigger binary, (similar to busybox), but might allow much much faster execution of long scripts. A very quick experiment shows that this might be worthwhile: date; for ((i=0;i100;i++)); do echo -n ; done; date; for ((i=0;i1;i++)); do /bin/echo -n ; done; date Prints: Thu Apr 9 07:05:19 BST 2009 Thu Apr 9 07:05:30 BST 2009 Thu Apr 9 07:05:47 BST 2009 In other words, 1E6 invocations of the builtin takes about 11 seconds, while 1E4 invocations of the standalone binary takes 17 seconds. The builtin echo is therefore about 150 times faster. What do you think? Richard
Re: idea: statically-linked busy-bash
Richard Neill rn...@hermes.cam.ac.uk writes: What I'm suggesting is to experimentally build a version of bash which has mv/cp/ls/stat/grep/ all built in. This is possible without rebuilding bash, see the documentation of the `enable' builtin. There are already a few examples in the bash distribution under examples/loadables. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 And now for something completely different.
Re: str1 str2 does not respect locale
Strings compared with [[ string1 string2 ]] are supposed to use the current locale, but they don't. It's a documentation error (but a long-standing one). The code has always used strcmp, not strcoll. how about change it to strcoll then ? I'll consider that as a possible enhancement for a future version. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer Chet Ramey, ITS, CWRUc...@case.eduhttp://tiswww.tis.case.edu/~chet/
Re: idea: statically-linked busy-bash
Andreas Schwab wrote: What I'm suggesting is to experimentally build a version of bash which has mv/cp/ls/stat/grep/ all built in. This is possible without rebuilding bash, see the documentation of the `enable' builtin. There are already a few examples in the bash distribution under examples/loadables. Thanks - that's interesting to know. However, most of the examples seem to be cut-down functions in some way - I can see that becoming incompatible/non-portable. What I was contemplating is to build in most of the actual gnu utils with the aim of making eg the builtin grep functionally identical to /bin/grep. Then I could make a system-wide change, replacing the regular bash shell with the fat-bash, and still have everything work... Richard
how to pass arguments with space inside?
Hi, I was wondering how to pass arguments with space inside. For example, my bash script looks like: #!/bin/bash ARG_OPTS= while [[ -n $1 ]]; ARG_OPTS=${ARG_OPTS} $1 shift done If I pass an argument like --options='-t 0 -v 0', then it would be splitted by the spaces inside, ie --options='-t, 0, -v and 0. How can I achieve what I wish? Thanks and regards! -- View this message in context: http://www.nabble.com/how-to-pass-arguments-with-space-inside--tp22978918p22978918.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: how to pass arguments with space inside?
On Thursday 09 April 2009 16:46:27 lehe wrote: I was wondering how to pass arguments with space inside. For example, my bash script looks like: #!/bin/bash ARG_OPTS= while [[ -n $1 ]]; ARG_OPTS=${ARG_OPTS} $1 shift done If I pass an argument like --options='-t 0 -v 0', then it would be splitted by the spaces inside, ie --options='-t, 0, -v and 0. How can I achieve what I wish? use arrays $ f=( a b c d) $ printf '%s\n' $...@]} a b c d -mike signature.asc Description: This is a digitally signed message part.
Re: how to pass arguments with space inside?
Thanks Mike. Could you explain it a little? I don't quite get it. How to apply this to argument parsing? Mike Frysinger wrote: On Thursday 09 April 2009 16:46:27 lehe wrote: I was wondering how to pass arguments with space inside. For example, my bash script looks like: #!/bin/bash ARG_OPTS= while [[ -n $1 ]]; ARG_OPTS=${ARG_OPTS} $1 shift done If I pass an argument like --options='-t 0 -v 0', then it would be splitted by the spaces inside, ie --options='-t, 0, -v and 0. How can I achieve what I wish? use arrays $ f=( a b c d) $ printf '%s\n' $...@]} a b c d -mike -- View this message in context: http://www.nabble.com/how-to-pass-arguments-with-space-inside--tp22978918p22979779.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: how to pass arguments with space inside?
Actually in the bash script there is a command that passes --options='-t 0 -v 0' as argument to an executable. I just found if I double quote --options='-t 0 -v 0' as argument to the bash script, then the '-t 0 -v 0' as a whole can be preserved until reaching the command invoking the executable. However the '-t 0 -v 0' is not passed as a whole to the executable, but splitted by spaces again. This may sounds like the problem of calling the executable, however when directly invoking the executable from terminal, either --options='-t 0 -v 0' or --options=-t 0 -v 0 without quoting could be passed successfully as argument. Hope that I could explain my question clearly enough. Really appreciate your advice! lehe wrote: Thanks Mike. Could you explain it a little? I don't quite get it. How to apply this to argument parsing? Mike Frysinger wrote: On Thursday 09 April 2009 16:46:27 lehe wrote: I was wondering how to pass arguments with space inside. For example, my bash script looks like: #!/bin/bash ARG_OPTS= while [[ -n $1 ]]; ARG_OPTS=${ARG_OPTS} $1 shift done If I pass an argument like --options='-t 0 -v 0', then it would be splitted by the spaces inside, ie --options='-t, 0, -v and 0. How can I achieve what I wish? use arrays $ f=( a b c d) $ printf '%s\n' $...@]} a b c d -mike -- View this message in context: http://www.nabble.com/how-to-pass-arguments-with-space-inside--tp22978918p22980759.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: how to pass arguments with space inside?
On Thursday 09 April 2009 17:47:59 lehe wrote: Thanks Mike. please do not top post Mike Frysinger wrote: On Thursday 09 April 2009 16:46:27 lehe wrote: I was wondering how to pass arguments with space inside. For example, my bash script looks like: #!/bin/bash ARG_OPTS= while [[ -n $1 ]]; ARG_OPTS=${ARG_OPTS} $1 shift done If I pass an argument like --options='-t 0 -v 0', then it would be splitted by the spaces inside, ie --options='-t, 0, -v and 0. How can I achieve what I wish? use arrays $ f=( a b c d) $ printf '%s\n' $...@]} a b c d Could you explain it a little? I don't quite get it. How to apply this to argument parsing? instead of gathering stuff into the variable ARG_OPTS, declare it as a variable and gather it there: declare -a ARG_OPTS while [[ -n $1 ]] ; do arg_opts[${#arg_op...@]}]=$1 shift done then use it like i showed and the argument grouping will be preserved: ${arg_op...@]} i imagine there are plenty of bash array howtos out there if you google -mike
Re: how to pass arguments with space inside?
Forgot to say in the bash script, the call to the executable is like: my_executable ${ARG_OPTS} lehe wrote: Actually in the bash script there is a command that passes --options='-t 0 -v 0' as argument to an executable. I just found if I double quote --options='-t 0 -v 0' as argument to the bash script, then the '-t 0 -v 0' as a whole can be preserved until reaching the command invoking the executable. However the '-t 0 -v 0' is not passed as a whole to the executable, but splitted by spaces again. This may sounds like the problem of calling the executable, however when directly invoking the executable from terminal, either --options='-t 0 -v 0' or --options=-t 0 -v 0 without quoting could be passed successfully as argument. Hope that I could explain my question clearly enough. Really appreciate your advice! lehe wrote: Thanks Mike. Could you explain it a little? I don't quite get it. How to apply this to argument parsing? Mike Frysinger wrote: On Thursday 09 April 2009 16:46:27 lehe wrote: I was wondering how to pass arguments with space inside. For example, my bash script looks like: #!/bin/bash ARG_OPTS= while [[ -n $1 ]]; ARG_OPTS=${ARG_OPTS} $1 shift done If I pass an argument like --options='-t 0 -v 0', then it would be splitted by the spaces inside, ie --options='-t, 0, -v and 0. How can I achieve what I wish? use arrays $ f=( a b c d) $ printf '%s\n' $...@]} a b c d -mike -- View this message in context: http://www.nabble.com/how-to-pass-arguments-with-space-inside--tp22978918p22980936.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: how to pass arguments with space inside?
Sorry. I won't top post again. I tried your way but ARG_OPTS only accept the first argument and ignore the rest. Mike Frysinger wrote: On Thursday 09 April 2009 17:47:59 lehe wrote: Thanks Mike. please do not top post Mike Frysinger wrote: On Thursday 09 April 2009 16:46:27 lehe wrote: I was wondering how to pass arguments with space inside. For example, my bash script looks like: #!/bin/bash ARG_OPTS= while [[ -n $1 ]]; ARG_OPTS=${ARG_OPTS} $1 shift done If I pass an argument like --options='-t 0 -v 0', then it would be splitted by the spaces inside, ie --options='-t, 0, -v and 0. How can I achieve what I wish? use arrays $ f=( a b c d) $ printf '%s\n' $...@]} a b c d Could you explain it a little? I don't quite get it. How to apply this to argument parsing? instead of gathering stuff into the variable ARG_OPTS, declare it as a variable and gather it there: declare -a ARG_OPTS while [[ -n $1 ]] ; do arg_opts[${#arg_op...@]}]=$1 shift done then use it like i showed and the argument grouping will be preserved: ${arg_op...@]} i imagine there are plenty of bash array howtos out there if you google -mike -- View this message in context: http://www.nabble.com/how-to-pass-arguments-with-space-inside--tp22978918p22981193.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: how to pass arguments with space inside?
On Thu, 9 Apr 2009, lehe wrote: Sorry. I won't top post again. You just did! I tried your way but ARG_OPTS only accept the first argument and ignore the rest. ARG_OPTS=( $@ ) All the arguments are now in the array ARG_OPTS: printf %s\n ${arg_op...@]} Mike Frysinger wrote: On Thursday 09 April 2009 17:47:59 lehe wrote: Thanks Mike. please do not top post Mike Frysinger wrote: On Thursday 09 April 2009 16:46:27 lehe wrote: I was wondering how to pass arguments with space inside. For example, my bash script looks like: #!/bin/bash ARG_OPTS= while [[ -n $1 ]]; ARG_OPTS=${ARG_OPTS} $1 shift done If I pass an argument like --options='-t 0 -v 0', then it would be splitted by the spaces inside, ie --options='-t, 0, -v and 0. How can I achieve what I wish? use arrays $ f=( a b c d) $ printf '%s\n' $...@]} a b c d Could you explain it a little? I don't quite get it. How to apply this to argument parsing? instead of gathering stuff into the variable ARG_OPTS, declare it as a variable and gather it there: declare -a ARG_OPTS while [[ -n $1 ]] ; do arg_opts[${#arg_op...@]}]=$1 shift done then use it like i showed and the argument grouping will be preserved: ${arg_op...@]} i imagine there are plenty of bash array howtos out there if you google -mike -- View this message in context: http://www.nabble.com/how-to-pass-arguments-with-space-inside--tp22978918p22981193.html Sent from the Gnu - Bash mailing list archive at Nabble.com. -- Chris F.A. Johnson, webmaster http://woodbine-gerrard.com = Do not reply to the From: address; use Reply-To: Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)