Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
01-04-2010, 01:18 PM
|
#1
|
LQ Newbie
Registered: Nov 2009
Posts: 17
Rep:
|
Nautilus Scripts Not Working (Fedora 12)
I'm trying to write some nautilus scripts.
I have a file (script) called fileType, on the scripts folder, that shows when i right click over a file, on the context menu, but it does nothing.
Code:
#!/bin/sh
for arg
do
filetype=$(file "$arg")
gdialog --title "File-Type Determinator" --msgbox "File $filetype" 200 200
done
Now, i tried gdialog on terminal, and i get a command not found.
So, i changed gdialog --title "File-Type Determinator" --msgbox "File $filetype" 200 200 to echo "File $filetype" but i see nothing.
To test, i added at the end of the script the command "peazip", and peazip starts, so the script is running, but the echo/gdialog lines are not working, any ideas?
Last edited by kwanbis; 01-04-2010 at 03:21 PM.
|
|
|
01-04-2010, 02:04 PM
|
#2
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep:
|
Quote:
Originally Posted by kwanbis
any ideas?
|
To get it to work, I had to change the script to look like the following:
Code:
#!/bin/sh
for arg
do
filetype=$(file "$arg")
# Uncomment the following for debugging
# echo "File $filetype"
zenity --info --title="File-Type Determinator" --text="File $filetype" --width=200 --height=200
done
At one point, I got a message saying gdialog was just a wrapper around zenity, and that I should execute zenity directly.
|
|
1 members found this post helpful.
|
01-04-2010, 03:14 PM
|
#3
|
LQ Newbie
Registered: Nov 2009
Posts: 17
Original Poster
Rep:
|
Quote:
Originally Posted by David1357
To get it to work, I had to change the script to look like the following:
...
At one point, I got a message saying gdialog was just a wrapper around zenity, and that I should execute zenity directly.
|
Thanks, that worked.
What is NOT working, is the echo command, as in:
echo "File $filetype" (without the comments).
Does the echo goes to a log? or i'm not seeing it cause i'm running as a nautilus script?
|
|
|
01-04-2010, 03:18 PM
|
#4
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep:
|
Quote:
Originally Posted by kwanbis
Does the echo goes to a log? or i'm not seeing it cause i'm running as a nautilus script?
|
You would only be able to see that output if you ran the script from a terminal window.
|
|
|
01-04-2010, 03:21 PM
|
#5
|
LQ Newbie
Registered: Nov 2009
Posts: 17
Original Poster
Rep:
|
Thanks, you have been mostly helpful.
|
|
|
01-05-2010, 11:16 AM
|
#6
|
LQ Newbie
Registered: Nov 2009
Posts: 17
Original Poster
Rep:
|
Ok, i finally got my script to work. Almost.
Code:
#!/bin/sh
for arg
do
pathName=`echo $NAUTILUS_SCRIPT_CURRENT_URI | sed -e 's|file:///|/|' -e 's|//|/|' -e 's|%20| |'`
fileName="$arg"
fullName=$pathName/$fileName
fileNoExt=${fileName%.*}
fullFolder=$pathName/$fileNoExt
# zenity --info --title="Executing..." --text="/usr/local/share/PeaZip/res/7z/7z x -o$fullFolder $fullName" --width=200 --height=200
/usr/local/share/PeaZip/res/7z/7z x -o"$fullFolder" "$fullName"
zenity --info --title="DONE Executing" --text="/usr/local/share/PeaZip/res/7z/7z x -o$fullFolder $fullName" --width=200 --height=200
done
Now, the problem is that 7z, executes hidden! I don't see it, i thought it would open a terminal like screen. But nothing.
What can it be? Can it be related to me not being able to see "echo XXX" messages also?
Last edited by kwanbis; 01-05-2010 at 11:19 AM.
|
|
|
01-05-2010, 12:08 PM
|
#7
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep:
|
Quote:
Originally Posted by kwanbis
Now, the problem is that 7z, executes hidden!
|
Why don't you use PeaZip instead of 7z? It has command line options like "-ext2here" that should give you the GUI. 7z is probably a command-line-only application that outputs text to stdout, which would only show up in a terminal.
I have put some questions inline with the code below.
Code:
#!/bin/sh
### Why not use /bin/bash?
for arg
do
pathName=`echo $NAUTILUS_SCRIPT_CURRENT_URI | sed -e 's|file:///|/|' -e 's|//|/|' -e 's|%20| |'`
fileName="$arg"
fullName=$pathName/$fileName
### With bash, the following can be fileNoExt=$(basename $fileName)
fileNoExt=${fileName%.*}
fullFolder=$pathName/$fileNoExt
### Why not use the following instead
/usr/local/share/PeaZip/bin/PeaZip -ext2folder
zenity --info --title="DONE Executing" --text="/usr/local/share/PeaZip/bin/PeaZip -ext2folder" --width=200 --height=200
done
|
|
|
01-05-2010, 12:13 PM
|
#8
|
LQ Newbie
Registered: Nov 2009
Posts: 17
Original Poster
Rep:
|
Yes, i know about peazip, in fact, it comes with some scripts in itself.
But i'm trying to understand why this is not working.
Like, shouldn't this scripts output to terminal?
Last edited by kwanbis; 01-05-2010 at 12:18 PM.
|
|
|
01-05-2010, 12:20 PM
|
#9
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep:
|
Quote:
Originally Posted by kwanbis
Like, shouldn't this scripts output to terminal?
|
Are you running the script from a terminal? If you are running this using the GUI, there is no TTY and all output goes to "/dev/null".
Even if you are running this from a terminal, the "res/7z/7z" binary may be designed to send all output to "/dev/null" as it appears to be a helper program.
Last edited by David1357; 01-05-2010 at 12:22 PM.
Reason: Added comment about 7z helper program
|
|
|
01-05-2010, 12:26 PM
|
#10
|
LQ Newbie
Registered: Nov 2009
Posts: 17
Original Poster
Rep:
|
I see what you mean.
So how comes i've seen plenty of shell script examples, where they use the "echo something2?
Shouldn't that work?
Also, fileNoExt=$(basename $fileName) gives nothing, i have tried it before.
I even changed to bash: #!/bin/bash
|
|
|
01-05-2010, 01:08 PM
|
#11
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep:
|
Quote:
Originally Posted by kwanbis
So how comes i've seen plenty of shell script examples, where they use the "echo something"?
|
Many times I write scripts that use "echo" and a log file. That way, even if the script runs without a TTY, I can see the output of the "echo". For example
Code:
#!/bin/bash
LOGFILE="/var/log/script.log"
# Notice that the first time I write to the log file
# I use the create file redirect ">". Also, I combine
# stderr with stdout using "2>&1", so that I log any
# errors.
echo "Starting the script..." > $LOGFILE 2>&1
# Notice that from this point on, I use the append file redirect ">>".
/usr/bin/something >> $LOGFILE 2>&1
echo "Done." >> $LOGFILE 2>&1
Quote:
Originally Posted by kwanbis
Also, fileNoExt=$(basename $fileName) gives nothing, i have tried it before.
|
Make sure your "bash" is really "bash". Run "ls -al $(which bash)". It may be a link to dash or something in "/etc/alternatives". In either case, it may not be the real full-featured "bash". Accept no substitutes...
|
|
|
01-05-2010, 01:15 PM
|
#12
|
LQ Newbie
Registered: Nov 2009
Posts: 17
Original Poster
Rep:
|
Thanks again. I do know about redirection, from my DOS BATCH days. I would try that then, if needed.
This is the output i get:
-rwxr-xr-x. 1 root root 861128 2009-12-11 08:51 /bin/bash
|
|
|
01-05-2010, 01:27 PM
|
#13
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep:
|
Quote:
Originally Posted by kwanbis
Thanks again. I do know about redirection, from my DOS BATCH days. I would try that then, if needed.
|
Yes, a lot of the Linux redirection syntax is very similar to DOS batch file syntax (and NT CMD file syntax for that matter...).
Quote:
Originally Posted by kwanbis
This is the output i get:
-rwxr-xr-x. 1 root root 861128 2009-12-11 08:51 /bin/bash
|
That looks correct. What does "bash --version" produce?
|
|
|
01-05-2010, 01:34 PM
|
#14
|
LQ Newbie
Registered: Nov 2009
Posts: 17
Original Poster
Rep:
|
I get:
Quote:
GNU bash, version 4.0.35(1)-release (i386-redhat-linux-gnu)
|
|
|
|
01-05-2010, 01:58 PM
|
#15
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep:
|
Quote:
Originally Posted by kwanbis
GNU bash, version 4.0.35(1)-release (i386-redhat-linux-gnu)
|
This is the second time I have seen someone post unexpected behaviour from version 4 of bash. Looks like "good enough" wasn't, so they changed it to "worse than before".
|
|
|
All times are GMT -5. The time now is 01:11 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|