Re: Variable variable name



On 2006-09-12, Samik R. wrote:
Chris F.A. Johnson wrote:

Fourth, consider using the positional parameters to make your
script more portable:

set -f
set -- `cat "$file"`

Thanks for your reply, Chris. I am using bash, so the 3rd comment is
applicable. Can you elucidate some more (or point to a reference) for
the fourth comment? I haven't used any of them earlier.

Using that method, each word of the file is placed into one of the
positional parameters, $1, $2, ..., ${10}, ${11}, etc., instead of
into a shell array (which most shells do not support, and is not
part of the POSIX standard).

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • Re: [opensuse] alias failure
    ... So it's just an accident that the following aliases all work as I ... It's uncommon for interactive shells to have any positional parameters ... Unlike the very limited capabilities of aliases, shell procedures ... I made a script with nothing but that in it, ...
    (SuSE)
  • Re: days-between
    ... > In fact, it doesn't work consistently in any shell, even bash, for ... > This (from the script under discussion) is wrong: ... It should work in any POSIX shell. ... > Chris F.A. Johnson ...
    (comp.unix.shell)
  • Re: Possible to export a readonly variable as readonly in bash?
    ... Chris, as for the .bash_logout script, I'll clarify it a bit ... I login (while the shell is being setup the following is executed ... unset FOO, no problemo, it is not readonly in this shell ...
    (comp.unix.shell)
  • Re: Bash: command output to variable
    ... Thank you very much Chris for your reply. ... Chris F.A. Johnson wrote: ... Also good coding style would be to define a shell variable like ... So one sees the magic numbers at the begin of the script. ...
    (comp.unix.shell)
  • Re: How to export environment variable to parent?
    ... Chris> If you want a script to affect the environment of the ... Chris> current shell, it must be run in the current shell, i.e. source ... "Rap music is our punishment for neglecting music education." ...
    (comp.unix.shell)