LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   getting rid of quotes when dragging a file into the terminal (https://www.linuxquestions.org/questions/programming-9/getting-rid-of-quotes-when-dragging-a-file-into-the-terminal-789984/)

nokangaroo 02-18-2010 12:31 PM

getting rid of quotes when dragging a file into the terminal
 
The following script will work when I type the path to the file I want to checksum, but not when I drag the file to the terminal because the linux terminal (unlike the Mac) automatically puts quotes around the file path, which causes an error. (Clarification: am referring to gnome-terminal. Thanks, GrapefruiTgirl.) I did not find anything in gconf-editor or anywhere else to alter this behaviour, and my post in Launchpad is unanswered so far. (the script in itself is not very useful, I just stumbled upon this error when experimenting with bash).

#!/bin/bash -x ## the x is just for debugging
echo 'paste the md5sum from the source website here:'
read SHOULD
echo 'type path to file here:'
read NAME ## fails when I drag
if [ "$SHOULD" = `openssl dgst -md5 < $NAME` ]; then ## or "$NAME"
echo 'verified'
else
echo 'verify failed!'
fi

So, is there a workaround for stripping the quotes from the input, or can I configure the terminal to not quote the input when I drag a file into it (which I would prefer?)

I am currently logged in from Mac OS, but the question refers to ubuntu karmic with which I dual boot.
ADMINISTRATORS: Thanks for the quick reply to my newbie question about posting new threads. Actually I don't see now what the difficulty was; I guess I was tired from trying to debug the above script (not funny).

GrapefruiTgirl 02-18-2010 12:38 PM

Out of curiosity, what if you change that line to:

Code:

if [ "$SHOULD" = "$(md5sum "$NAME")" ]; then
Does that work as you expect?

I admit I'm not using gnome-terminal, so I cannot comment specifically on its configuration or what may be causing that behaviour, but I want to make clear that when you say "linux terminal", you are making a generalization :) because there are loads of different terminals, all of which can act differently depending on how they are configured.

If this IS a gnome-terminal specific thing, hopefully someone who uses that terminal, can shed some light, if my suggestion does not help.

Sasha

nokangaroo 02-18-2010 12:57 PM

Will try and report

nokangaroo 02-18-2010 01:15 PM

Sorry, no go, even when I type instead of drag. And the dollar sign is pink instead of blue in gedit. I really think this is not a bash issue but a bug in gnome-terminal (I filed a bug report in Launchpad; let's see what happens.)

nokangaroo 02-19-2010 10:15 AM

Solved, of sorts. This will do the trick, but I still don't know how to configure gnome-terminal to not generate quotes in the first place.

#!/bin/bash -x
TMP=`mktemp`
echo 'paste the md5sum from the source website here:'
read SHOULD
echo 'drag downloaded file here:'
read NAME; echo $NAME >> $TMP
NAME1=`sed "s/'*//g" $TMP` ## this strips the quotes from the filename
rm -f $TMP
if [ "$SHOULD" = `openssl dgst -md5 < $NAME1` ]; then
echo 'verified'
else
echo 'verify failed!'
fi

So now I can verify md5sums without doing any typing, but I need not add that this workaround is very *sedentary* and uncool. On the Mac the script works in its original form.

ntubski 02-19-2010 12:23 PM

You don't need the temporary file:

Code:

NAME=`echo $NAME | sed "s/^'\|'$//g"` ## this strips the quotes from the beginning and of the filename, not the middle.

nokangaroo 02-21-2010 03:49 PM

Thanks, ntubski. Just found another solution, well hidden in /etc/bash_completion.

#!/bin/bash -x
echo 'paste the md5sum from the source website here:'
read SHOULD
echo 'drag downloaded file here:'
read NAME
NAME1=`eval echo "$NAME"` ## doesn't seem to be well known!
if [ "$SHOULD" = `openssl dgst -md5 < "$NAME1"` ]; then
echo 'verified'
else
echo 'verify failed!'
fi

A little more elegant than the sedentary solution, but not much ;-)


All times are GMT -5. The time now is 07:12 PM.