Gentoo Archives: gentoo-user

From: Alex Schuster <wonko@×××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: emerge of ksh93 erroring out.. who can interpret
Date: Mon, 14 Jan 2008 15:45:07
Message-Id: 200801141638.42281.wonko@wonkology.org
In Reply to: [gentoo-user] Re: emerge of ksh93 erroring out.. who can interpret by reader@newsguy.com
1 reader@×××××××.com writes:
2
3 > So I'm interested in what I might run into. So far it looks like it
4 > would be ALMOST as easy as symlinking ksh to bash in /bin.
5
6 Uh, this sounds scary :)
7
8 > The two big things I see that will cause that not to work are lots of
9 > calls to `print' and that bash does not understand the easy way you
10 > can create an array in ksh:
11 > `set -A array somecmd'
12 > creating an array of the output of somecmd.
13 >
14 > So the print calls and array creation would cause failure in nearly
15 > all my scripts.
16 >
17 > Someone on comp.unix.shell pointed out I could create a
18 > `print() { echo -e "$@" }'
19 > function in bash and add that to my old ksh scripts. So that would
20 > cover the print calls in most cases but still pondering the array
21 > part.
22
23 I do not know about ksh, but if the former statement creates an array with
24 the i'th element containing the i'th word of somecmd's output, it should
25 work like this:
26 array=( $( somecmd ) )
27
28 If you need the i'th line, not the i'th word, do it like this, changing the
29 internal field separator to newlines only:
30 oldIFS=$IFS
31 IFS=$'\n'
32 array=( $( somecmd ) )
33 IFS=$oldIFS
34
35 If you want to keep your notation, something like this might work. If the
36 first parameter of a call to set is -A, it creates the array, or else it
37 calls the bash set builtin:
38
39 set ()
40 {
41 if [[ $1 == -A ]]
42 then
43 eval "$2=( $( $3 ) )"
44 else
45 set "$@"
46 fi
47 }
48
49
50 > I don't have so many with array calls but enough that it would be some
51 > work to fix.
52 >
53 > But back to your comments. "The bugs. [...]"
54 >
55 > Can you cite some actual examples of what you are talking about, with
56 > enough detail so I can see what you mean? Maybe include one or two of
57 > the workarounds you are tired of dealing with?
58
59 I also had trouble with some bash bugs(*), and have some workarounds in my
60 scripts, in case they run with older bash versions. But as I cannot ensure
61 the client systems run kash or zsh, I did not bother to learn them, and
62 chose bash as my shell. It's amazing what it can do, but I guess zsh and
63 ksh can do the same, or even more.
64
65 (*) One was that I once needed to escape backslashes in ${//...} notations,
66 but now I must not do so any more:
67 (( BASH_VERSINFO < 3 )) &&
68 ospath=${1//\\\\//} ||
69 ospath=${1//\\//}
70
71 The other problem was with the =~ notation and quoting of the regular
72 expression not being allowed any more. Workaround is to define a variable
73 (foo) with the expression: [[ "blabla" =~ $foo ]]
74
75 Wonko
76 --
77 gentoo-user@l.g.o mailing list

Replies