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.

5
  • What does /home/user23/bin/n-youtube-dl look like?
    – geirha
    Apr 13, 2014 at 8:36
  • github.com/rg3/youtube-dl/blob/master/youtube-dl I dont think that this matters at all. Apr 13, 2014 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, 2014 at 8:39
  • Actually I was wrong I just made a test and its just closing the term Apr 13, 2014 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. Apr 13, 2014 at 8:54

2 Answers 2

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 "$@"
0
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.

1
  • 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, 2014 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .