718266 718266 - 8 months ago 59
Linux Question

How to write this command in bash so that it works: gnome-terminal -e urlsnarf -i $interface | cut -d\" -f4

I'm writing a small program in bash and I need to use this command:

gnome-terminal -e urlsnarf -i $interface | cut -d\" -f4

When I execute it, I get the error
Failed to parse arguments: Unknown option -i
. I've tried to run it with double quotes:

gnome-terminal -e "urlsnarf -i $interface | cut -d\" -f4"

But it gives me another error:
Argument to "--command/-e" is not a valid command: Text ended before matching quote was found for . (The text was 'urlsnarf -i wlan0 | cut -d" -f4')"

I've also tried running it with single quotes:

gnome-terminal -e 'urlsnarf -i $interface | cut -d\" -f4'

Nothing happens, but I don't get an error either.
If I run the command without the
gnome-terminal -e
, everything works flawlessly, but I need it to open a new terminal and execute the command there. The variable
is defined, and I think the problem comes from the double quotes in the command. I'm using the latest version of Kali Linux. Also, I've tried running it as:

gnome-terminal -x urlsnarf -i $interface \|cut -d\" -f4

But I get the same result as the single quotes scenario, nothing happens, but I don't get an error either.

gnome-terminal -e urlsnarf -i $interface | cut -d\" -f4

Doesn't work because gnome-terminal takes -i as one of its own arguments.

gnome-terminal -e "urlsnarf -i $interface | cut -d\" -f4"

May be failing because your -d argument is getting its \ stripped before gnome-terminal sees it, so it sees an unmatched ". You can try adding more \s, though it's a well-known road to hell.

gnome-terminal -e 'urlsnarf -i $interface | cut -d\" -f4'

Can't work because $interface won't be resolved inside single quotes.


gnome-terminal -e "urlsnarf -i $interface | cut '-d"' -f4"

Also, I found this thread where it's revealed that gnome-terminal uses spaces as whitespace and you can fool it by using tabs instead.