Re: shorthand attempt at 'basename file .ext'

2008-03-29 Thread Chris F.A. Johnson
On 2008-03-28, Eric Blake wrote: > Chris F.A. Johnson gmail.com> writes: > >> >>You can find a shell function to replace the external basename >>command at: <http://cfaj.freeshell.org/shell/scripts/basename-sh>. > > Except that your example

Re: read -d on a terminal

2008-06-20 Thread Chris F.A. Johnson
miting was entered. -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) .

Re: some variable level issues

2008-06-30 Thread Chris F.A. Johnson
On 2008-06-29, Matt Zyzik wrote: > bug-bash, > 2. $( want any newlines chopped off. So to remedy this, I do the > following: "IFS='' read -r -d '' var < file". Firstly, is this safe > to do, and are there any other ways? Secondly, it appears to be very > slow compared to $(http://Woodbine-Gerr

Re: Bash/readline enhancement: wish to pre-set initial value of input text

2008-07-09 Thread Chris F.A. Johnson
On 2008-07-08, Richard Neill wrote: > Dear All, > > When using read, it would be really neat to be able to pre-fill the form > with a default (or previous) value. > > For example, a script which wants you to enter your name, and thinks > that my name is Richard, but that I might want to correct it.

Re: inconsistent treatment of backslash-bang

2008-07-16 Thread Chris F.A. Johnson
gt; > If you want fully sh-compatible behavior, you have to turn off history > expansion (set +o history). I find it adequate to set histchars to an empty string. -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: bash: request for a way to return variables to the parent of a subshell

2008-07-22 Thread Chris F.A. Johnson
[[ "$LINE" =~ example-file ]]; then MATCH=true; echo "Match-1" fi done if [ "$MATCH" == true ] ;then echo "Match-2" fi } -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: function name bug ?

2008-07-30 Thread Chris F.A. Johnson
error near unexpected token `(' > abz,caz and cba work Do you have an alias named 'cbz'? If so, unalias it before defining the function. -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: how do I write a shell script to batch rename files in a directory?

2008-08-29 Thread Chris F.A. Johnson
or i in *.gif?; do mv --verbose $i ${i%\?}; done That will break if there are pathological filenames. for i in *.gif?; do mv -v -- "$i" "${i%\?}" done -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: File renaming using SED in BASH

2008-09-21 Thread Chris F.A. Johnson
in * > do > chg=echo $f |sed 's:(www.somewhere.net)::' That assigns echo to $chg and tries to execute $f. Use command substitution. > mv $f $chg > done for f in * do chg=$( echo "$f" | sed 's:(www.somewhere.net)::' ) mv "$f" "$chg"

Re: nullglob breaks unset of arrays

2008-09-25 Thread Chris F.A. Johnson
-u nullglob > # remove first entry > unset my_array[0] > echo "Array [EMAIL PROTECTED]" > shopt -s nullglob > # remove first entry > unset my_array[0] There is no longer any my_array[0] to unset. Try: unset my_array[1] > echo

Re: [bash 3.2.39] File descriptor 10 is always duplicated from 0 and cannot be closed

2008-10-31 Thread Chris F.A. Johnson
1 do printf . done echo exec 11<&- ) .... -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: Is this a bash wildcard bug?

2008-11-20 Thread Chris F.A. Johnson
r--r-- 1 root root 0 Nov 20 12:22 xa > -rw-r--r-- 1 root root 0 Nov 20 12:22 xA > > # ls -l x[A-Z] > -rw-r--r-- 1 root root 0 Nov 20 12:22 xA > > Any ideas? You are using a locale that conflates upper- and lowercase as aAbBcC...yYzZ. Try it with: export LC_ALL=C

Re: [bash-testers] Re: case modification operators misbehaviour?

2009-01-14 Thread Chris F.A. Johnson
t" matches that, and should be changed. Interesting that it works > with ^^s (for "Tesst" then), but for all "s", of course. man bash4: ... the ^ and , expansions match and convert only the first

Terminal state with read -st1

2009-02-27 Thread Chris F.A. Johnson
In bash4.0, the terminal is not reset if this is times out: read -st1 -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: Terminal state with read -st1

2009-03-02 Thread Chris F.A. Johnson
On Mon, 2 Mar 2009, Chet Ramey wrote: Chris F.A. Johnson wrote: In bash4.0, the terminal is not reset if this is times out: read -st1 Thanks for the report. The cleanup functions were not called on timeout. The attached patch fixes things for me. Thanks; that works. -- Chris F.A

Completion crashes the shell

2009-03-02 Thread Chris F.A. Johnson
CWORD]}*-sh` ) COMPREPLY=( "${comprep...@]%-sh}" ) } Aborting...Aborted -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: Completion crashes the shell

2009-03-02 Thread Chris F.A. Johnson
. -- 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)

Feature request

2009-03-10 Thread Chris F.A. Johnson
I would like to see read's -d option expanded to accept a string of characters, any one of which would terminate input. The character which terminates input should be stored in a variable, e.g., $REPLY_END. -- Chris F.A. Johnson, webmaster <http://woodbine-ger

Re: delete elements from an array...

2009-03-10 Thread Chris F.A. Johnson
unset array2[n] break ;; esac n=$(( $n + 1 )) done printf "%s\n" "${arra...@]}" echo printf "%s\n" "${arra...@]}" -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> = Do not reply to the Fro

Re: loop through records

2009-03-11 Thread Chris F.A. Johnson
ot necessary in this example) for REC in "${arra...@]}" do set -- $REC printf "Field 1: %s Field 2: %s\n" "$1" "$2" done -- 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)

Re: Feature Idea: Enhanced Tab Completion

2009-03-21 Thread Chris F.A. Johnson
ve already entered on the command line. For example, if I type 'gr' and up-arrow, I will get the last grep command I used. Keep pressing for earlier instances. -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> = Do not reply to the From:

Re: using mapfile is extreamly slow compared to oldfashinod ways to read files

2009-03-26 Thread Chris F.A. Johnson
e) If you want to remove trailing spaces as well: mapfile < <(sed -e 's/^ *//' -e 's/ *$//' file) Chet, how about an option to mapfile that strips leading and/or trailing spaces? Another useful option would be to remove newlines. -- Chris F.A. Johnson, we

Re: using mapfile is extreamly slow compared to oldfashinod ways to read files

2009-03-27 Thread Chris F.A. Johnson
On Fri, 27 Mar 2009, Lennart Schultz wrote: Chris, I agree with you to use the right tool at the right time, and mapfile seems not to be the right tool for my problem, but I will just give you some facts of my observations: using a fast tool like egrep just to find a simple string in my

Re: feature-request: brief syntax for $(type -p somecommand)

2009-04-02 Thread Chris F.A. Johnson
., and the current incantation is just long enough to be annoying. Use a function, e.g.: p() { pp=$( type -p "$@" ) } -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> = Do not reply to the From: address; use Reply-To: Aut

Re: feature-request: brief syntax for $(type -p somecommand)

2009-04-02 Thread Chris F.A. Johnson
On Thu, 2 Apr 2009, Mike Coleman wrote: On Thu, Apr 2, 2009 at 11:33 AM, Chris F.A. Johnson wrote: On Thu, 2 Apr 2009, Mike Coleman wrote: [Oops--I sent that incomplete.] It would be nice if there was some really brief syntax for $(type -p somecommand) I find myself using this all day

Re: Brace expansion

2009-04-04 Thread Chris F.A. Johnson
nnig with 0 are required to be interpreted as octal numbers. 08 and 08 ar enot valid octal numbers. for i in 0{1..9} 10; do printf "%02d\n" "$[i#0}";done Or: printf "%02d\n" {1..10} Or, in bash4.0: printf "%s\n" {01..10} -- Chris F.A.

Re: how to pass arguments with space inside?

2009-04-09 Thread Chris F.A. Johnson
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)

Re: how to pass arguments with space inside?

2009-04-11 Thread Chris F.A. Johnson
command in a variable, but the complex cases always fail!" http://mywiki.wooledge.org/BashFAQ/005 "How can I use array variables?" -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> = Do not reply to the From: address; use Reply-To:

Re: passing arrays as parameters to functions

2009-04-18 Thread Chris F.A. Johnson
parameters are my two integer arguments, but I'd like them to be optional. The size of the array is not fixed. func() { local f_array eval "f_array=( \"\${...@]}\" )" printf "%s\n" "${f_arr...@]}" } a=( qw er ty ui op ) func a -- Chris F.A

extglob

2009-05-15 Thread Chris F.A. Johnson
Am I missing something, or are these extended globbing patterns equivalent to a plain asterisk? ?(pattern-list) Matches zero or one occurrence of the given patterns *(pattern-list) Matches zero or more occurrences of the given patterns -- Chris F.A. Johnson, webmaster <h

Re: extglob

2009-05-16 Thread Chris F.A. Johnson
On Sat, 16 May 2009, Pierre Gaston wrote: > On Sat, May 16, 2009 at 2:44 AM, Chris F.A. Johnson > wrote: > > > > Am I missing something, or are these extended globbing patterns > > equivalent to a plain asterisk? > > > > ?(pattern-list) Matches zero or

read -e bug

2009-05-27 Thread Chris F.A. Johnson
This is nothing new; it happens in all versions of bash: printf "Enter something: " read -e whatever Press a key, then cursor left (or ^A); the cursor moves to the beginning of the line, over "E" instead of over the character just entered. -- Chris F.A. Johnson, web

Re: read -e bug

2009-05-28 Thread Chris F.A. Johnson
; > beginning of the line, over "E" instead of over the character just > > entered. > > This isn't a bug; that's where readline thinks the cursor is. Why would it think that? It's wrong. > If you want to use a prompt, use `read -p'. I like

Re: read -e bug

2009-05-28 Thread Chris F.A. Johnson
On Thu, 28 May 2009, Pierre Gaston wrote: > On Thu, May 28, 2009 at 3:52 PM, Chris F.A. Johnson > wrote: > > On Thu, 28 May 2009, Chet Ramey wrote: > > > >> > > >> > This is nothing new; it happens in all versions of bash: > >> > >

Help help missing m option in synopsis

2009-05-29 Thread Chris F.A. Johnson
time consumed by pipeline's execution. times - Display process times. read - Read a line from the standard input and split it into fields. readarray - Read lines from a file into an array variable. readonly - Mark shell variables as unchangeable. -- Chris F.A. Johnson, webmaster

Re: printf has weird behaviour when parsing zero padded numbers

2009-06-22 Thread Chris F.A. Johnson
leading zeroes in a > single regular expression: > > shopt -s extglob > n=${n##+(0)} Or, with standard globbing: ${n#"${n%%[!0]*}"} > b) Use a loop to remove all leading zeroes, one at a time: > > while [[ $n = 0* ]]; do n=${n#0}; done >

Re: $\n doesn't get expanded between double-quotes

2009-07-02 Thread Chris F.A. Johnson
not a variable. As the man page says: Words of the form $'string' are treated specially. Note "Words". Inside double quotes, $'\n' is not a word. > > If this is a feature, not a bug, then is there a better way to include > newli

Re: $\n doesn't get expanded between double-quotes

2009-07-03 Thread Chris F.A. Johnson
'\n\n'Here are the log-files for > $(date)$'\n\n'Regards,$'\n\n'$SENDER" > > then this doesn't work. There are ways around it, such as: > - building up the string in pieces or > - EMAIL_BODY=$(echo -

printf -v doesn't allow array assignment

2009-07-17 Thread Chris F.A. Johnson
$ printf -v q[2] "%s" "$RANDOM" bash: printf: `q[2]': not a valid identifier I know I can work around it with a temporary variable, but it would be nice if it could be done in a single step. -- Chris F.A. Johnson &

mapfile callback

2009-07-17 Thread Chris F.A. Johnson
mapfile callback code is executed in a subshell. Would it be possible to make it execute in the current shell? With mapfile -c1, this would make it possible to work on a file without an explicit loop, making it much faster. -- Chris F.A. Johnson <h

Re: mapfile callback

2009-07-19 Thread Chris F.A. Johnson
On Sun, 19 Jul 2009, Chet Ramey wrote: Chris F.A. Johnson wrote: mapfile callback code is executed in a subshell. It's not. It's executed in the same context as an `eval' or a trap command. So it is. Great! I wonder what I was doing wrong before. -- Chr

Re: mapfile callback

2009-07-19 Thread Chris F.A. Johnson
On Mon, 20 Jul 2009, Pierre Gaston wrote: On Mon, Jul 20, 2009 at 5:46 AM, Chris F.A. Johnson wrote: On Sun, 19 Jul 2009, Chet Ramey wrote: Chris F.A. Johnson wrote: mapfile callback code is executed in a subshell. It's not. It's executed in the same context as an `eval&

Re: read -t 0 not supported? (poll)

2009-07-22 Thread Chris F.A. Johnson
On Wed, 22 Jul 2009, Marc Herbert wrote: It seems polling using "read -t 0" is not supported. It is supported in bash 4.0. -- Chris F.A. Johnson <http://cfaj.freeshell.org> ===

Re: Errors when patching bash4.0

2009-07-22 Thread Chris F.A. Johnson
k" fails on every patch file. What am I doing wrong? Thanks, -Alex -- Chris F.A. Johnson <http://cfaj.freeshell.org> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: Bash script file naming problem?

2009-07-25 Thread Chris F.A. Johnson
On Fri, 24 Jul 2009, michael rice wrote: > Is there a problem with naming a bash script file "script"? I'm using Fedora > 11. Most systems already have a command called 'script'. It is not a good idea to use the names of existing commands for your scri

Re: Bash script file naming problem?

2009-07-25 Thread Chris F.A. Johnson
"which" command is not a good way to see how a command will be resolved. It is an external command (and at least one version will not work with bash), and it doesn't know about shell functions or aliases. The command to use is 'type'. With the -a option,

Ordering in associative array expansion

2009-07-28 Thread Chris F.A. Johnson
What is the algorithm for order of expansion of associative arrays? Single-letter subscripts are expanded alphabetically, but longer subscripts are not. -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.

Re: parse error running builtins from array

2009-07-28 Thread Chris F.A. Johnson
e 1: syntax error: unexpected end of file > > well, there isn't a missing " AFAICT, and playing around with them has not > helped. Does anyone have a way out of this? Take a look at the arguments you are actually using: printf "%s\n" ${cc[1]} Use eval: f

Re: parse error running builtins from array

2009-07-29 Thread Chris F.A. Johnson
On Wed, 29 Jul 2009, mk27 wrote: > >Take a look at the arguments you are actually using: > > [root~] printf "%s" ${cc[1]} > bash-c"timels-l" > > Again, I can't see the missing " Try using the code I posted: printf "%s\n"

read -t0 doesn't pick up waiting characters

2009-08-08 Thread Chris F.A. Johnson
ntain '[' and $x to contain 'A'. However, they are empty. They do pick up the characters if I change delay to .0001. -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> ===

Re: unset associative array may cause segfault

2009-08-25 Thread Chris F.A. Johnson
Here is my fast patch. > > I already fixed it, thanks. Do you have a patch for it? It's not fixed with the patches posted so far. -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> ===

Re: doing simple math in bash :: prb with leading zero

2009-09-01 Thread Chris F.A. Johnson
this in the past as well...). > > Where are you getting the value 'lastmo' from? > > If from 'something like date +"%m"', maybe you could strip off the leading > zero? I.e.: > > lastmo=$(echo "$lastmo"|sed -r 's/0+([0-9])/\1/'

Re: doing simple math in bash :: prb with leading zero

2009-09-01 Thread Chris F.A. Johnson
On Tue, 1 Sep 2009, ken wrote: > Doing very simple math in bash fails if a number begins with a zero (0). Numbers beginning with 0 are base 8 (octal). 08 and 09 are not valid octal numbers. -- Chris F.A. Johnson, webmaster <http://woodbine-gerra

Re: Strange compgen behaviour

2009-09-24 Thread Chris F.A. Johnson
items a, b, c, d, e, f, whereas I would > expect 3 items 'a b', 'c d', 'e f'. It looks like compgen splits the argument > to -W on $IFS _and_ whitespace. Or am I missing something? -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com>

Re: Bug in array populating does not respect quotes

2009-09-24 Thread Chris F.A. Johnson
gt; ~$ samplestring="x y 'z k'" > ~$ samplearray=( $samplestring ) eval "samplearray=( $samplestring )" > ~$ echo ${samplearray[2]} > 'z -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: Real easy questions. Please answer

2009-09-25 Thread Chris F.A. Johnson
this... > > Counter() > { > echo $# > } > Counter $IDs > but that just seems stupid That's a perfectly good way of doing it, but you will want to turn off filename expansion if there's a chance that the value may contain wildcards: set -f Counter $ID

Re: ignoring comments in a 'cat' call

2009-10-07 Thread Chris F.A. Johnson
comments or is there a better > alternative to cat in this case? aptitude install $(cut -d ' ' -f1 programs) -y -- Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: Cannot form valid test expressions that involve brackets as string comparison targets

2009-10-07 Thread Chris F.A. Johnson
;${basePic:4:1}" = '\)' ] > then > echo "Got brackets" > fi > > Fix: > Unsure, I think the bracket parsing should not be treated as > expression delimiters if they are enclosed in quotes? > If they are bare, then trea

Re: [OT] Re: how to start in "overwrite-mode"

2009-10-28 Thread Chris F.A. Johnson
> > Bourne shell has no functions at all. Had. Only before 1984. Since then it has had functions. The first shell I used, the Bourne shell on AT&T SVR3.2, had functions. -- Chris F.A. Johnson, webmaster

Re: OT: Getting MySQL fields with embedded spaces into array

2009-10-29 Thread Chris F.A. Johnson
nd store the contents of the query in an array > > > > SIGS=$(mysql ${COM_LINE} -e"use ${DB}; SELECT sig from ${table} WHERE > > sig_file='0';") > > That is not an array. It's just a string (scalar) variable. > > > ## Set IFS = line feed

Re: value too great for base (error token is "0008")

2009-11-04 Thread Chris F.A. Johnson
uires either a loop, or the > > use of extended globs. > > Not true. You can do it via POSIX and without a loop by using an > intermediate variable: > > foo=00081 > bar=${foo%%[!0]*} > foo=${foo#$bar}} Or even without an intermediate variable: foo=${foo#${foo%%[!0]*}

Re: Error handling question

2009-11-09 Thread Chris F.A. Johnson
Instead I use "set -e" systematically. It > works. It is unpredictable but I do not to care: a safety net with a few > holes is way better than none at all. The very few times I actually want > to ignore an error I just append " || true" to the corresponding > co

Re: IFS handling and read

2009-11-30 Thread Chris F.A. Johnson
uts information to the screen, for example (this is much oversimplified): { x=$(( $something * 2 )) printf "%d\n" "$x" } Now, I want to modify the output. I pipe it through a formatting command: { x=$(( $something * 2 )) printf "%d\n" "$

Re: IFS handling and read

2009-11-30 Thread Chris F.A. Johnson
<(command) thing) and here strings, > you should be able to do all your reads without subshells. Or, to be portable, use a here document: IFS=: read a b <<. 1:2 . This works with the output of commands, too: IFS=- read year month day <<. $(date +%Y-%m-%d) . -- Chr

Re: IFS handling and read

2009-11-30 Thread Chris F.A. Johnson
On Mon, 30 Nov 2009, Lhunath (Maarten B.) wrote: > On 30 Nov 2009, at 15:56, Chris F.A. Johnson wrote: > > > > On Mon, 30 Nov 2009, Greg Wooledge wrote: > > > >> On Mon, Nov 30, 2009 at 11:46:03AM +0100, Lhunath (Maarten B.) wrote: > >>> Don't u

Re: best way to test for empty dir?

2009-12-10 Thread Chris F.A. Johnson
ho $1/*$2)" = "x$1"'/*'"$2" > } > > > Warning: I find neither "noglob" nor "ls" elegant, sorry! is_file() { for f do [ -f "$f" ] && return done return 1 }

Re: best way to test for empty dir?

2009-12-11 Thread Chris F.A. Johnson
On Fri, 11 Dec 2009, Sven Mascheck wrote: ... > comp.unix.shell might match well here and could be entertaining - > IMHO worth to migrate; objections? This has been discussed more than once in c.u.s; check the archives. -- Chris F.A. Johnson, webmaster <http:/

Re: best way to test for empty dir?

2009-12-11 Thread Chris F.A. Johnson
On Fri, 11 Dec 2009, Antonio Macchi wrote: > is_file() > { > [ -f "$1" ] && return > return 1 > } > > is_file /path/to/dir/* || echo empty > > > > you don't need to check more than the first element You may need to; it de

Re: add a way to declare global variables

2009-12-12 Thread Chris F.A. Johnson
> It _would_ make some sense, however, if its counterpart 'global' existed, as > it could help clarify the intended usage of the variable. Of the three, local is the only command I use. It says exactly what it does. -- Chris F.A. Johnson, webmaster <http://

Re: BASH Command substitution

2009-12-17 Thread Chris F.A. Johnson
e Command substitution chapter > the proper interpretation logic. > > > --- Comment #3 From SpanKY 2009-12-17 10:32:32 [reply] --- > > those two examples are not equivalent. your first snippet boils down to: > echo \'alfa beta\' > > this bugzi

Re: variable assignment in string returning function

2010-01-27 Thread Chris F.A. Johnson
pt name="optimus" foo () { if [ "$name" = "optimus" ] then gang="good" echo "Nice behaviour" return 0 else gang="bad" echo "Naughty behaviour" return 1 fi } b

Re: bash killed by filecompletion feature if filename(s) contain '*' character

2010-01-30 Thread Chris F.A. Johnson
> > Description: > bash died while word completion if filename contains a '*' character > > Repeat-By: > touch file\*1 > touch file\*2 > chmod +x file* > ./file[tab][tab] No problem here in 3.2, 4.0 or 4.1 -- Chris F.A. Johnson

Re: Passing variables to and from custom programs

2010-02-07 Thread Chris F.A. Johnson
On Sun, 7 Feb 2010, Mike Stroyan wrote: > On Sat, Feb 06, 2010 at 05:35:21PM -0800, DennisW wrote: > > On Feb 6, 5:37 pm, djackn wrote: > > > Result = myIpExec(${IPaddr1} ${IPaddr2} ${IPaddr3} ${IPaddr4}) > > > > > > myIpExec is a c program that normally uses scanf to prompt the user > > > fo

Re: Is there a special variable for the directory where the script is in?

2010-02-11 Thread Chris F.A. Johnson
ly gives the full path to the file, so: "${0%/*}" -- Chris F.A. Johnson <http://cfajohnson.com> === Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pr

Re: Is there a special variable for the directory where the script is in?

2010-02-11 Thread Chris F.A. Johnson
On Thu, 11 Feb 2010, Eric Blake wrote: > According to Chris F.A. Johnson on 2/11/2010 4:23 PM: > > On Fri, 12 Feb 2010, Peng Yu wrote: > > > >> $0 gives the file name of the script. I could use several shell > >> command to get the directory where the script

Re: Namespace problem with pipe into a braced group

2010-02-23 Thread Chris F.A. Johnson
# output: 2 > a=1; echo foo|{ a=2; }; echo $a # output: 1 > > Bug or feature? Standard behaviour; all components of a pipeline are executed in a subshell. -- Chris F.A. Johnson <http://cfajohnson.com>

Re: Confused about how bash breaks input into words

2010-02-23 Thread Chris F.A. Johnson
an unquoted $ character consumes until the > end of the shell substitution, command substitution, or arithmetic > substitution, and that entire scan becomes part of the current word being > parsed). > > > This confuses me because, intuitively, I feel that the command substitutio

Re: Return status of command substitution with $(...) "gets lost"

2010-03-04 Thread Chris F.A. Johnson
ieved from the $? variable. > > Important detail: The local variable is declared and defined in > the same step with "local VARNAME=$(do something)". > > Problem: The $? variable is always 0 after that statement. The return status is that of the comm

Re: How cd to a directory with special characters like environment\<\-?

2010-04-08 Thread Chris F.A. Johnson
directory Try using the same spelling in both instances. -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: How cd to a directory with special characters like environment\<\-?

2010-04-09 Thread Chris F.A. Johnson
environmen\<\- > > -bash: cd: environmen<-: No such file or directory > > In such situations I find completion (TAB) really great since it does > the hard quoting work for you (and does no typo). That, or up-arrow (or Ctrl-P) to recall previous command. -- Chri

Re: declare -A a=b crashes bash

2010-04-09 Thread Chris F.A. Johnson
neric #59-Ubuntu SMP Wed Mar 24 > 07:28:27 UTC 2010 x86_64 GNU/Linux > Machine Type: x86_64-pc-linux-gnu > > Bash Version: 4.0 > Patch Level: 33 > Release Status: release > > Description: > Typing 'declare -A a=b' crashes bash with a segmentation fau

Re: How cd to a directory with special characters like environment\<\-?

2010-04-09 Thread Chris F.A. Johnson
On Fri, 9 Apr 2010, Greg Wooledge wrote: > On Fri, Apr 09, 2010 at 11:59:20AM -0400, Chris F.A. Johnson wrote: > > On Fri, 9 Apr 2010, Marc Herbert wrote: > > > Le 08/04/2010 22:58, Peng Yu a ?crit : > > > > > $ mkdir environment\<\- > > > > $

Re: Help with sed

2010-04-17 Thread Chris F.A. Johnson
pmi[:space:]--auto/p'); If you don't quote $content, echo will put it all on one line. content=$(echo "$content" | sed -n '/mandriva/,/fi;}/p'); content=$(echo "$content" | sed '/^\s*urpmi[:space:]--auto/p'); -- Chris F.A. Johnson, <

Re: How to make a directory name with '/' in it?

2010-05-16 Thread Chris F.A. Johnson
racters that cannot be in a file or directory name: / and NUL. -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: How to autocomplete after 'which'?

2010-05-21 Thread Chris F.A. Johnson
" is > > often misleading, compare for instance: > > > > type pwd > > which pwd > > > > "which" is misleading in many other cases. > > Since pwd is a shell command, when /bin/pwd is actually used? In > shells that don't have buil

Re: Question if bug: declaration of an associative array within a function

2010-06-15 Thread Chris F.A. Johnson
nfortunate side effect from 'declare' being a duplicate of the (non-standard) typeset builtin. If would be much more useful (and semantically accurate), if it just did what its name implies, and left the 'local' builtin for declaring variable local to a f

Re: How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Chris F.A. Johnson
%s\n" "$i" done Or, without a loop: printf "%s\n" "$@" > f a 'b c' d e f g > > > $ ./main.sh > a > b > c > d > e > f > g > > -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: Bash cannot kill itself?

2010-06-29 Thread Chris F.A. Johnson
600 > > ### END OF THE SCRIPT ### > > It does not work as I expected. The running script was not terminated after > 5 seconds. So what's wrong here? $$ refers to the subshell. Try: trap 'echo killed by SIGALRM; exit 1' ALRM function wait_kill() { sleep

Re: Bash cannot kill itself?

2010-06-29 Thread Chris F.A. Johnson
On Wed, 30 Jun 2010, Clark J. Wang wrote: > On Wed, Jun 30, 2010 at 12:38 PM, Chris F.A. Johnson > wrote: > > > On Wed, 30 Jun 2010, Clark J. Wang wrote: > > > > > I have a bash script like this: > > > > > > #!/bin/bash > > > > > &g

Re: Bash cannot kill itself?

2010-06-29 Thread Chris F.A. Johnson
in") shell you use. > > > Then what's the problem with my script in my original mail? Seems like Bash > does not handle the signal in a real-time way. The special variable $$ refers to the current process, even if it has the same numeric value as the parent script. -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: Naming convention of bash script filenames

2010-07-11 Thread Chris F.A. Johnson
oduction copy. (The support scripts for this are in the last chapter of my first book, Shell Scripting Recipes".) -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Re: basic pattern match Question..."newbie" doesn't understand (!...@#$@$)

2010-08-01 Thread Chris F.A. Johnson
"not found"; fi It prints nothing. Seems like such a basic concept. Sorry, this newbie needs help on such trivial matters. :-( When quoted, the right-hand argument is matched as a string, not an expression. -- Chris F.A. Johnson, <http://cfajohnson.com> Author:

Re: RFE -or- Howto?

2010-08-02 Thread Chris F.A. Johnson
s. A minor loss of "prettiness" is negligible compared to portability. It makes it clear that you are no longer doing what I want, a multi-variable assignment. It *is* a multi-variable assignment. But that's my sense of what looks readable in codeYMMV. On 8/2/2010

Re: Issues when func name is the same with an alias

2010-08-05 Thread Chris F.A. Johnson
write much more code if I define them all as functions. This is "much more code": F(){ find "$@"; } than: alias F=find I don't think functions are better than aliases here. Any idea? Many reasons why functions are generally better have already been gi

Re: Bash style of if-then-else?

2010-08-23 Thread Chris F.A. Johnson
s a significant advantage over standard syntax. [[ ... ]] is not standard, and offers little over the standard syntax. -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Prob

Re: Encoding multiple filenames in a single variable

2010-08-29 Thread Chris F.A. Johnson
in the filename. Either separate them with newlines, or (non-POSIX) use an array. ## POSIX NL=' ' files=${files:+$files$NL}$nextfile ## Array files+=( "$nextfile" ) -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linu

Re: How to deal with space in command line?

2010-09-18 Thread Chris F.A. Johnson
ere are special characters such as space by adding '\' in front them? This will supply as many files as possible as arguments to stat: find . -type f -exec stat --printf "%y %n\n" + -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Sc

Re: asking for a better way to implement this

2010-09-26 Thread Chris F.A. Johnson
On Sun, 26 Sep 2010, Christopher Roy Bratusek wrote: btw. How can I remove the last arguement ${!#} ? I tried args=${@:-${!#}} but that won't work. args=( "$@" ) unset args[$#-1] set -- "${ar...@]}" -- Chris F.A. Johnson, <http://cfajohnson.com>

Re: asking for a better way to implement this

2010-09-27 Thread Chris F.A. Johnson
er You get the idea, I hope. Or you might put it in a script, expecting to be prompted, and lose files you need. Aliases are not expanded in a script. -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apr

Re: bash auto complete malloc 'assertion botched' error

2010-10-09 Thread Chris F.A. Johnson
unknown:0: assertion botched free: start and end chunk sizes differ Aborting... Repeat-By: typing cd '\ or ls "\ will reproduce the above bug Using: GNU bash, version 4.1.7(2)-release (amd64-portbld-freebsd8.1) does not seem to produce that error. Nor does 4.0.28(2)-release on

<    1   2   3   4   5   >