0
#!/bin/bash
gnome-terminal --command='/home/user23/bin/n-youtube-dl "$1"'

I want to pass the argument passed to this script to the other script started in the terminal. But this starts endless gnome terminals.

Can you explain why that is and how to make this work?

I am running zsh has my main shell if that matters, the terminal starts the script in zsh then I guess.

Update:

#!/bin/bash
gnome-terminal --command='echo "WTF"'
read -p "Press [Enter] key"

Is just closing the term faster then I can see WTF. Isn't it supposed to stop? Same goes for replacing the WTF with $1 again, no respawn.

  • What does /home/user23/bin/n-youtube-dl look like? – geirha Apr 13 '14 at 8:36
  • github.com/rg3/youtube-dl/blob/master/youtube-dl I dont think that this matters at all. – redanimalwar Apr 13 '14 at 8:37
  • ok, that doesn't seem to spawn a terminal, so it doesn't answer the question of why it's recursing. Are you sure n-youtube-dl is that python script and not actually your wrapper itself? – geirha Apr 13 '14 at 8:39
  • Actually I was wrong I just made a test and its just closing the term – redanimalwar Apr 13 '14 at 8:42
  • Oh damn I am too tired, yes you are right, that was actaully the wrapper itself and I tought that it has something to do with the $1 lol. – redanimalwar Apr 13 '14 at 8:54
1

To run a command in gnome-terminal, and safely pass arguments to it, you should use the -x option, since this avoids having the line parsed by two shells.

#!/usr/bin/env bash
gnome-terminal -x youtube-dl "$@"
1
#!/bin/bash
gnome-terminal -x bash -c "cd ~/Downloads/youtube; youtube-dl \"$@\"; read -p \"Press [Enter] key\""

This is how I actually solved this.

  • Don't embed the arguments into the script. That is very error prone. Instead, pass them on as arguments: gnome-terminal -x bash -c 'cd ~/Downloads/youtube && youtube-dl "$@"; read -p "Press [Enter] key"' _ "$@" – geirha Apr 13 '14 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.