Linux - NewbieThis 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.
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.
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?
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.
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?
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
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
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...
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".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.