OILS / test / gold / word-eval.sh View on Github | oilshell.org

57 lines, 6 significant
1#!/usr/bin/env bash
2#
3# Demo of word evaluation.
4#
5# Usage:
6# ./hard.sh <function name>
7#
8# Bug with the current algorithm: IFS=\\
9
10set -- 'a*b' 'c d'
11typeset -a myarray
12myarray=('w x' 'y*z', 'bin')
13space=' '
14glob='*h b*' # anything that ends with h, then anything that begins with b
15
16spec/bin/argv.py -"$@"-$space-"$space-${myarray[@]}"/$glob
17
18# ['-a b', 'c d-', '- -w x', 'y z,', 'bin/opypy-osh', 'bin/osh', 'bin/sh', 'benchmarks', 'bin', 'build']
19
20# I have a single word.
21# I evaluate all the parts:
22#
23# "$@" -> ArrayPartValue
24# $space -> StringPartValue
25# "$space" -> StringPartValue
26# $myarray -> ArrayPartValue
27# $glob -> StringPartValue
28#
29# Then I _MakeWordFrames. Each frame is (frag, list)
30
31# (frag, do_split_elide)
32#
33# [ ('-a b', False) ]
34# [ ('c d', False), ('-', False), (' ', True), ('-', False), (' ', False),
35# ('-', False), ('w x', False) ]
36# [ ('y z', False) ]
37# [ ('bin', False), ('*h b*', True) ]
38
39
40# Then for each frame, do _EvalWordFrame. Respect the boolean, and do
41# glob.GlobEscape or self.splitter.Escape(frag)
42
43# '-a b'
44# -> Glob escape
45# '-a b'
46# -> Split EScape
47# '-a\ b'
48
49# 'c\ d-'
50# '-'
51
52# Possible fix to IFS='\' problem: do globbing and splitting in two completely
53# separate steps. The Split() function should respect [(frag, bool do_split) ...]
54#
55# If not splitting, then it's easy to emit the span.
56
57