LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 06-20-2006, 03:38 AM   #1
Sabinou
Member
 
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Rep: Reputation: 30
Help with creating a small script ?


Hello folks

I'm totally new to scripting (I only created one before, and it was six lines long ^^), so my question is plainly : can you tell me if the script I want to create is something possible ?

Here's what I want to do : it's to create a script that, when ran from inside a folder, will start an existing command-line program, add the current folder's name to the program's parameters (i.e. -s "folder's name"), and add *.* to the parameters.

The program works fine when I manually add the folder's name and *.* to its parameters, but that's a hassle, I'd love a way to automatize that.

I know that may look foolish for a question, but I honestly don't know if that's something possible.
Can you tell me if that can be done ? (erm, and how ? ^_^)

Thanks
 
Old 06-20-2006, 03:42 AM   #2
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Code:
#!/bin/sh

/usr/bin/programname -s $(pwd) *.*
exit 0
One-liner
 
Old 06-20-2006, 05:36 AM   #3
Sabinou
Member
 
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Original Poster
Rep: Reputation: 30
Awesome ^_^
Thanks Cs-cam ^_^
I'll remember that !

But erm, I noticed on the trying a little problem : that only works if there aren't spaces in the folder's name or in the path to the folder :/
Is there maybe a solution, or... not, in your opinion ?
 
Old 06-20-2006, 05:41 AM   #4
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
You need to set the IFS variable in the script, eg
Code:
#!/bin/sh
IFS=$'\n'
/usr/bin/programname -s $(pwd) *.*
exit 0
 
Old 06-20-2006, 05:44 AM   #5
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
Or I think it would work if you put quotes around $(pwd), so it would be "$(pwd)"
 
Old 06-20-2006, 06:42 AM   #6
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
The quotes would be a neater solution and would work just as well. Changing variables like IFS can lead to trouble if say you decided to expand the script later you might get some odd behaviour.
 
Old 06-20-2006, 06:44 AM   #7
Sabinou
Member
 
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Original Poster
Rep: Reputation: 30
Thanks Binary_y2k2, with quotes, the spaces are taken into account
Things are getting surprising : I tested, and observed one unexpected problem : the thing that is taken into account isn't only the folder name... it's the full path including the folder name !

Let's say my folder is in "/home/sabin/folders/folder I want to process", then the name that will be processed will be ""/home/sabin/folders/folder I want to process", instead of just "folder I want to process".

Sigh... Would you know the trick ?
I'd need to seriously work on scripting
 
Old 06-20-2006, 06:49 AM   #8
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
edit:
ok insted of "$(pwd)" try "$(basename "$PWD")"

Last edited by binary_y2k2; 06-20-2006 at 06:53 AM.
 
Old 06-20-2006, 07:01 AM   #9
Sabinou
Member
 
Registered: Jan 2006
Location: France
Distribution: Debian Wheezy, Webmin + Virtualmin (remote dedi)
Posts: 214

Original Poster
Rep: Reputation: 30
That worked ^_^
It's my final thanks, i'm really grateful
 
  


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
creating small boot .iso w/ network drivers eramm Linux - Networking 1 02-05-2006 05:05 AM
small script Kassel Programming 2 11-19-2004 04:22 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
Please Help with a small script ? juglugs Programming 2 11-14-2001 02:39 AM
Small Script msj Linux - Newbie 2 08-27-2001 06:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:12 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