I am trying to get the address of a window using wmctrl and assign it to a variable.
When I do this in a terminal (zsh)
ADDRESS=$(wmctrl -l | grep -E "Picture in picture" | awk 'NR==2 {print $1}')
echo "address is: ${ADDRESS}"
Output: address is: 0x0400001f
Which is great as that’s the expected result
However when I do the same in a script:
./pop_up.sh
#!/bin/bash
ADDRESS=$(wmctrl -l | grep -E "Picture in picture" | awk 'NR==2 {print $1}')
echo "address is: ${ADDRESS}"
Output: address is:
Nothing is printed for address even though its the same command which makes me think I am not assigning the output of the command properly or its a problem with how I am using awk (?).
What I tried:
- using backticks (“) instead of $() but still no change
- When I do ADDRESS=date, I get back the date as expected so I am not sure why assigning the output of date works but assigning the output of the command above doesn’t.
- I also tried diagnosing the issue by splitting the three commands awk, grep and wmctrl. In this case, I get the echo output of wmctrl and grep but when I reach awk it does not output the result of filtering the address from the line…
I am not too familiar with bash scripts/awk so can anyone please help me see what I am doing wrong here?
thanks
Kakowi Desu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4