0

I am using centos Linux. I wanted to open a new tab in the current window terminal from a script file named 'myscript'. I use the following script

#!/bin/bash
WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID # line 5
xdotool key ctrl+shift+t #line 6
wmctrl -i -a $WID # line 7

referred from this link Open a new tab in gnome-terminal using command line. I run the script in this way source myscript and i get an error saying Illegal variable name. How to fix this ? Note! I don't want to open new tabs in a new window.

Community
  • 1
  • 1
user_rak
  • 85
  • 4
  • 17
  • What shell are you using? `csh` or `tcsh`? – Etan Reisner Jul 13 '15 at 12:40
  • @etan how can i know that ? – user_rak Jul 13 '15 at 12:44
  • What does `echo "$0"` say? What does `declare -p SHELL` say? I'm guessing the answers are `tcsh` or `csh` and `declare: Command not found.` which will indicate that you are using `tcsh`/`csh` and that script is for bash. If you run it as `./script.sh` it should work even from `tcsh` though but will not when run directly or sourced. – Etan Reisner Jul 13 '15 at 13:12
  • `echo "$0"` gives `/bin/tcsh` and `declare -p SHELL` gives `declare: Command not found.` running ./myscript gives: `./myscript: line 5: xdotool: command not found ./myscript: line 6: xdotool: command not found ./myscript: line 7: wmctrl: command not found` – user_rak Jul 13 '15 at 13:23
  • That's `tcsh` then like I guessed. Do you have `xdotool` and `wmctrl` installed because it doesn't look like it. Those errors indicate running it like that got past the `Illegal variable name` problem you were having (because it ran with `/bin/bash` from the shebang line) but had trouble because the commands the script uses aren't available. – Etan Reisner Jul 13 '15 at 13:30
  • @Etan Is there a way to check if xdotool and wmctrl is installed ? If so how? – user_rak Jul 13 '15 at 13:46
  • Those errors are pretty clear that they aren't. I don't know if those are packaged for CentOS in the default repositories. You might be able to find them in the EPEL repos or in IUS or assuming it isn't in either of those it might be in the nux desktop repository. See the [Repositories](http://wiki.centos.org/AdditionalResources/Repositories) page for more info about these repositories. – Etan Reisner Jul 13 '15 at 15:39

1 Answers1

1

The problem is the $(commands) statement. Try to use `` instead:

set WID=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}'`
xdotool windowfocus $WID
xdotool key ctrl+shift+t
wmctrl -i -a $WID
Christian
  • 132
  • 1
  • 14
  • I got `xdotool: Command not found. xdotool: Command not found. wmctrl: Command not found.` – user_rak Jul 13 '15 at 13:29
  • Yes, `csh`/`tcsh` supports the older backtick command substitution syntax so this will "fix" that problem. But using `tcsh` in the first place is already a "problem" as-is trying to use the wrong shell for the script. – Etan Reisner Jul 13 '15 at 13:31