Basically I want to convert a bash script which swaps workspaces between monitors, with one keybind, into a POSIX shell, but I don't know how to replace the redirection operator <<< with a sh compliant operator/command.
Original bash script:
My workaround script:
Output:
Any Idea?
Original bash script:
Bash:
#!/usr/bin/env bash
# requires jq
DISPLAY_CONFIG=($(i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"'))
for ROW in "${DISPLAY_CONFIG[@]}"
do
IFS=':'
read -ra CONFIG <<< "${ROW}"
if [ "${CONFIG[0]}" != "null" ] && [ "${CONFIG[1]}" != "null" ]; then
echo "moving ${CONFIG[1]} right..."
i3-msg -- workspace --no-auto-back-and-forth "${CONFIG[1]}"
i3-msg -- move workspace to output right
fi
done
My workaround script:
C:
#!/bin/sh
# requires jq
DISPLAY_CONFIG=$(i3-msg -t get_outputs | jq -r '.[]|select(.active == true) |"\(.current_workspace)"')
for ROW in "${DISPLAY_CONFIG[@]}"
do
IFS=' '
read -r CONFIG <<< "${ROW}"
i3-msg -- workspace --no-auto-back-and-forth "${CONFIG}"
i3-msg -- move workspace to output right
done
Output:
Code:
sh -vx display_swap
#!/bin/sh
# requires jq
DISPLAY_CONFIG=$(i3-msg -t get_outputs | jq -r '.[]|select(.active == true) |"\(.current_workspace)"')
+ i3-msg -t get_outputs
+ jq -r '.[]|select(.active == true) |"\(.current_workspace)"'
+ DISPLAY_CONFIG=$'1
2 '
for ROW in "${DISPLAY_CONFIG[@]}"
do
IFS=' '
read -r CONFIG <<< "${ROW}"
display_swap: 9: Syntax error: redirection unexpected (expecting word)
Any Idea?