File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 142142
143143 =my_script 'a b c' d e=
144144
145+ Do you want a more advanced way to use arrays in shell? use =jq=. [[https://alurm.github.io/blog/2025-08-07-first-class-lists-in-shells.html][Link]]
145146** Pass Arrays around
146147 #+begin_src bash
147148 a=('Track 01.mp3' 'Track 02.mp3')
@@ -2508,6 +2509,48 @@ The tricks here:
25082509 docker run --rm -ti -v =(echo "OHAI"):/tmp/foo ubuntu cat /tmp/foo
25092510 #+end_src
25102511
2512+
2513+ ** =(), the crazy stuff
2514+ The problem to solve here is to
2515+ `echo "A\nB" | { grep 'B' ; grep 'A' }`.
2516+
2517+ With `tee >(grep 'B') >(grep 'A')` it doesn't maintain the order.
2518+
2519+ echo -e "A\nB" | tee >(grep "B") | grep "A" it doesn't maintain order either
2520+
2521+ Another approach is:
2522+ foo() { 0s - [25-03-25 14:52]
2523+ grep 'B' /dev/stdin
2524+ grep A /dev/stdin
2525+ }
2526+
2527+ but the problem there is that stdin gets consumed and the second doesn't get anything.
2528+
2529+ foo() { 0s - [25-03-25 14:52]
2530+ grep 'B' $1
2531+ grep A $1
2532+ }
2533+ and then call it with foo <(echo "A\nB") . but doesn't work, because <() creates a pipe.
2534+ and then call it with foo =(echo "A\nB") . This works. Ok, we have a way.
2535+
2536+ foo() {
2537+ grep 'B' =(cat /dev/stdin)
2538+ grep A =(cat /dev/stdin)
2539+ }
2540+ that still doesn't work, because the moment you do `cat /dev/stdin`, /dev/stdin gets emptied
2541+
2542+ So we can create a function that makes /dev/stdin a file instead of a pipe
2543+
2544+ bar() {
2545+ grep 'B' $1
2546+ grep A $1
2547+ }
2548+
2549+ foo() {
2550+ bar =(cat /dev/stdin)
2551+ }
2552+
2553+ echo "A\nB"| foo . AND IT WORKS NOW
25112554* TODO patterns
25122555** just use cat/netcat/pipes with <()
25132556
You can’t perform that action at this time.
0 commit comments