1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# more odds and ends for nofork command substitution
# make sure parsing is right within conditional commands
[[ ${ echo -n "[${ echo -n foo; }]" ; } == '[foo]' ]] || echo bad 1
[[ "${ echo -n "[${ echo -n foo; }]" ; }" == '[foo]' ]] || echo bad 1
# mix multiple calls to parse_and_execute
got=$(eval 'x=${ for i in test; do case $i in test) echo .;; esac; done; }' ; echo $x)
echo $got
# mix compound assignment and nofork command substitution
: ${ a=(1 2 3 ${ echo 4;} ); }
declare -p a
unset a
# function execution with side effects
int=0
incr()
{
echo incr: $int
(( int++ ))
}
: ${ incr; }
: ${ incr; }
declare -p int
# expansion inside here-document body
int=0
: <<EOF
${ incr; }
EOF
echo after here-doc: $int
# jobs list in nofork command substitution
sleep 1 &
sleep 1 &
jl1=${ jobs; }
printf '%s\n' "$jl1"
jl2=${ jobs; }
printf '%s\n' "$jl2"
# nofork command substitution doesn't affect the shell's random number sequence
RANDOM=42
echo $RANDOM ${ echo $RANDOM; }
RANDOM=42
echo $RANDOM $RANDOM
# here-documents and other word expansions with comsub/funsub on the rhs
exec 4<<EOF
we should try rhs
${word-$(echo comsub)}
and
${word-${ echo funsub; }}
in here-documents
EOF
cat <&4
exec 4<&-
echo after all they ${word-$(echo work here)}
echo and ${word-${ echo work here; }}
|