LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-04-2013, 07:04 PM   #1
ThomasHunter
LQ Newbie
 
Registered: Jan 2013
Location: Colorado
Distribution: Ubuntu 12.04 LTS
Posts: 2

Rep: Reputation: Disabled
Getting selected file name(s) in bash script - nautilus/gnome2


Hello, I want to point out that I am very new to the world of bash script programming. Okay, so I made a couple very simple scripts to compile C++/Allegro/Java programs for me like this one:
Code:
#!/bin/bash
c++ *_src.cpp -o Out.cpp
I put this in my ~/.gnome2/nautilus-scripts folder so that I could right-click a _src file and compile it. HOWEVER this (obviously) only works if I have a single _src file in a directory. I need to be able to select a file, right-click, and compile it; having an output of the same file name and that one only. I do not know how to get a selected file name through script though, so I just used an asterisk. Thanks for any help in advance!

Last edited by ThomasHunter; 01-04-2013 at 07:37 PM.
 
Old 01-05-2013, 08:35 PM   #2
ThomasHunter
LQ Newbie
 
Registered: Jan 2013
Location: Colorado
Distribution: Ubuntu 12.04 LTS
Posts: 2

Original Poster
Rep: Reputation: Disabled
Solution

So for anyone who's looking at this in the future, I found that you can use the $* variable to get the selected file name. I edited my above code to this:
Code:
#!/bin/bash
c++ $* -o ConsoleOut.cpp
if [ $? -eq 0 ] #$? is the variable that says whether the last command is true or false
then
	zenity --info --title="Success - Compilation"  --text="Compilation Successful."
else
	zenity --error --title="Error - Ccompilation"  --text="Something went wrong - compile in terminal."
fi
So I hope this helps someone.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] get selected file name bash script gujedan Programming 7 03-14-2011 12:04 PM
I need a script to Delete Selected BackupFiles and Restore selected backup file finalwar Linux - Newbie 3 07-20-2010 02:10 AM
Opening a nautilus via a bash cron script rose_bud4201 Programming 3 06-20-2008 09:26 AM
Weird Nautilus Bash Script Problem fatsheep Programming 2 11-19-2006 04:51 PM
GNOME2 and Nautilus address bar smiley_lauf Linux - Newbie 1 01-13-2006 10:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration