Hey all, I have this tiny bash script to grab my i3 workspace and set it, the problem I think is scope my X var is not being seen at all by the set function.
#!/bin/bash
function main {
# If the argument is empty then run both functions else only run provided function as argument $1.
[ -z "$1" ] && { get; set; } || $1
}
function get {
X=$(i3-msg -t get_workspaces | jq -r '.[] | select(.visible == true).name')
for var in "${X[@]}"
do
echo "$var"
done
}
function set {
sleep 5;
for var in "${X[@]}"
do
echo "$var"
i3-msg workspace $var
sleep 1;
done
}
main "$@"
would declaring the variable outside the function work, and if so why? (If I remember correctly there is local variables).
I am going to test this, but just in case it doesn't work, or even if it does I'm confused.