Re: Unable to do a for loop in "here document"
On Tue, Jul 08, 2008 at 08:44:47PM -0700, Mr Aras wrote: [...] > #!/bin/sh > sh <<-EOF > for word in hello world > do > echo word = $word > done > EOF > > output is: > word = > word = > > > Can someone tell me why this doesn't work? I've been going nuts trying to > figure this one out. [...] Variables are expanded in here documents unless you quote something in the terminator. So the above becomes: sh <<-EOF for word in hello world do echo word = done EOF You want: sh <<-\EOF for word in hello world do echo word = $word done EOF (or E"O"F or 'EOF' ...) -- Stéphane
Re: Problem with "for loop" in "here document"
put a backslash in front of the $ so that it is not substituted when the here document read, but later when you run that code. On 7/9/08, Mr Aras <[EMAIL PROTECTED]> wrote: > > Hi, > > I've been trying to implement a "for loop" in a "here document" but the > "name" is never assigned to any of the items in the list. > > e.g. > > #!/bin/sh > sh <<-EOF > for word in hello world > do > echo word = $word > done > EOF > > output is: > word = > word = > > > Can someone tell me why this doesn't work? I've been going nuts trying to > figure this one out. > > > -- > View this message in context: > http://www.nabble.com/Problem-with-%22for-loop%22-in-%22here-document%22-tp18353951p18353951.html > Sent from the Gnu - Bash mailing list archive at Nabble.com. > > > >
Re: setting locales
Chet Ramey wrote: In file locale.c, function get_locale_var, locale = default_locale;/* system-dependent; not really portable. should it be "C"? */ default_locale contains string returned by calling setlocale(LC_ALL,NULL); and we then use this string to assign locale for LC_'every_other' and this is not right way. Why we simple don't call setlocale(LC_ALL,default_locale)? The final code will be shorter and more readable... Bash does most of the locale-setting itself for two reasons. 1. setlocale() calls getenv() to obtain the values for the variables it's interested in. Not all systems allow getenv() to be replaced or interposed, so setlocale() would see stale data. 2. Users expect shell variables to affect the locale for the shell. Since setlocale() looks in the environment, these changes would not be applied. In any event, calling setlocale(LC_ALL, default_locale) is rarely the right thing to do, since it doesn't allow users to mix locales between categories (e.g., LC_COLLATE=C; LC_CTYPE=C; LC_MESSAGES=de_DE.UTF-8). Chet Yeah, I got your point. Nevertheless I do this small patch, which parse default_locale and try to find if category is set. diff -up bash-3.2/locale.c.rr bash-3.2/locale.c --- bash-3.2/locale.c.rr 2006-07-27 15:38:43.0 +0200 +++ bash-3.2/locale.c 2008-07-08 13:43:51.0 +0200 @@ -264,6 +264,41 @@ set_default_lang () set_lang ("LANG", v); } +/* Try to find value of locale variable in default_locale. + Return found value or NULL. */ +char * +find_var_in_default (var) + char *var; +{ + char *begin = strstr (default_locale, var); + + if (begin) +{ /* var is in default */ + int size = 0; + char *end = NULL; + char *value = NULL; + + begin = index (begin, '='); + if (!begin) +return (char *) NULL; /* Bad syntax of locale string */ + + begin++; /* value begins behind '=' */ + end = index (begin, ';'); /* here may ends value of var */ + size = end ? end - begin : strlen (begin); + + value = (char *) malloc (size + 1); + if(!value) +return (char *) NULL; /* malloc error */ + + value = strncpy (value, begin, size); + value[size] = '\0'; + return value; +} + + return (char *) NULL; /* var isn't in default */ +} + + /* Get the value of one of the locale variables (LC_MESSAGES, LC_CTYPE). The precedence is as POSIX.2 specifies: LC_ALL has precedence over the specific locale variables, and LANG, if set, is used as the default. */ @@ -280,6 +315,8 @@ get_locale_var (var) if (locale == 0 || *locale == 0) locale = lang; if (locale == 0 || *locale == 0) +locale = find_var_in_default(var); + if (locale == 0 || *locale == 0) locale = default_locale; /* system-dependent; not really portable. should it be "C"? */ return (locale); begin:vcard fn:Roman Rakus n:Rakus;Roman org:Red Hat;BaseOS adr:;;;Brno;;;Czech Republic email;internet:[EMAIL PROTECTED] title:Associate software engineer tel;cell:+420 774 891 861 x-mozilla-html:FALSE version:2.1 end:vcard
Bash tty session leader (tcsetpgrp) race condition - help requested
Hi all, I posted a bug report to bug-bash on June 21 about this seemingly long-standing problem, and I followed up with more info pointing to the cause a few days ago. I have not gotten any responses yet, and I am anxious to continue helping to find a solution. I am sorry not to include a patch (yet), but I am stuck where I really need more bash internals knowledge. If anyone here is knowledgeable about the job control and tty stuff and can help, please let me know. Here is a link to my second email in the previous thread: http://www.nabble.com/forum/Permalink.jtp?root=18047733&post=18305346&page=y Thanks, Joe
Re: Bash/readline enhancement: wish to pre-set initial value of input text
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. > Alternatively, this would be useful within a loop, to allow correction > of previously-entered text, without fully typing it again. > > So, I propose an extra option, -i, to read, which will set the initial > value of the text following the prompt. I like that idea. In the meantime, I use: history -s "$DEFAULT" read -ep "Enter name (up arrow for '$DEFAULT'): " name > For example, > > > #!/bin/bash > read -e -p 'Enter your name: ' -i 'Richard' NAME > echo "Hello, $NAME" > > > This would print: >Enter your name: Richard > I would then be able to edit the part after the prompt, and change it to: >Enter your name: R. Neill > This would then print: >Hello, R. Neill > > > > It is equivalent to the following in PHP/HTML: > > Enter your name: > > > An alternative syntax might be to make use of stdin for the read > command, eg: > echo 'Richard' | read -e -p 'Enter your name: ' NAME > though I think I prefer the -i. > > > I hope you like this idea. Thanks very much for your help. > > Richard > > > .