LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-27-2011, 08:50 AM   #1
apurak
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Rep: Reputation: 0
a script


The existing Linux program foo2bar takes as its only argument the name of a single foo file and converts it to an appropriately-named bar file. Provide a script that when executed will run foo2bar against all foo files in the current directory.

How would you make that script executable?
 
Old 01-27-2011, 09:00 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
Quote:
Originally Posted by apurak View Post
The existing Linux program foo2bar takes as its only argument the name of a single foo file and converts it to an appropriately-named bar file. Provide a script that when executed will run foo2bar against all foo files in the current directory.

How would you make that script executable?
Hi and welcome to LQ. It's against LQ rules to help with homework. Please do some research/ look at your course notes and write a script. We'll be happy to help you when you're stuck at some point, but don't expect us to do the work for you.

HTH
 
Old 01-27-2011, 09:44 AM   #3
apurak
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Hi HTH,

Fair enough. The first part, I don’t know how to do it nor I was not able to find anything . The second part , maybe :
chmod 755 foo2bar
run . foo2bar
 
Old 01-27-2011, 09:49 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Assuming this is for bash shell, all you need is a for loop.

Otherwise, you could always use:
  • find to find the files
  • while to loop
  • read to assign a file name to a given variable on each iteration

About chmod, they don't say anything about the rest of permissions. So, I wouldn't touch them. I would just use chmod +x.
 
Old 01-27-2011, 09:53 AM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
Quote:
Originally Posted by apurak View Post
Hi HTH,

Fair enough. The first part, I don’t know how to do it nor I was not able to find anything . The second part , maybe :
chmod 755 foo2bar
run . foo2bar
As far as the first problem is concerned, I don't think there's any way out apart from googling for 'bash tutorial' and start learning it (key words: for loop, positional parameters)

Code:
chmod +x foo2bar
./foo2bar

Last edited by sycamorex; 01-27-2011 at 09:54 AM.
 
Old 01-27-2011, 10:02 AM   #6
apurak
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Original Poster
Rep: Reputation: 0
is this correct:
ls * | xargs foo2bar
 
Old 01-27-2011, 10:09 AM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
^ good idea but not quite. according to the problem you want to filter on just foo files and not everything in the current directory. also you need a method of naming the output bar file.
 
Old 01-27-2011, 10:17 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
I wouldn't use ls for anything serious. I guess it's ok for an exercise, but it's better not to grow confident on wrong methods, this is the "why".

http://mywiki.wooledge.org/ParsingLs

xargs is not a good thing in this case, for the reason that it passes a lot of parameters each time, and the "foo2bar" tool that you will be calling accepts only one. As said above, you need some kind of loop to read the file names one by one, so you can call "foo2bar" with a single file name on each iteration.
 
Old 01-27-2011, 04:36 PM   #9
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 12,542
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Welcome to LQ!

Quote:
Originally Posted by apurak View Post
The existing Linux program foo2bar takes as its only argument the name of a single foo file and converts it to an appropriately-named bar file. Provide a script that when executed will run foo2bar against all foo files in the current directory.

How would you make that script executable?
Quote:
excerpt from LQ Rules; Do not expect LQ members to do your homework - you will learn much more by doing it yourself.
As the rules states you will learn more by doing it yourself. The rules do not state that LQ members cannot assist you as you have found out.

Along with your text and instructor's help we can aid or direct you to a solution.

These links are to aid you to gaining some understanding. Sure some may seem beyond a newbie skill level but you must start somewhere;



Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Bash Beginners Guide
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking



The above links and others can be found at 'Slackware-Links'. More than just Slackware® links!
 
Old 01-27-2011, 07:39 PM   #10
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
@etouchqa

There's a separate thread for testing whatever one wants to test.
http://www.linuxquestions.org/questi...-issue-745067/

Please do not hijack other threads... and welcome to LQ
 
Old 04-07-2012, 04:40 AM   #11
papagu
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
the script itself

Quote:
Originally Posted by apurak View Post
The existing Linux program foo2bar takes as its only argument the name of a single foo file and converts it to an appropriately-named bar file. Provide a script that when executed will run foo2bar against all foo files in the current directory...
Well how is actually your script look like?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 08:29 PM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 10:56 AM
set variables in a bash script; ansi PS1 color script donnied Programming 4 11-21-2007 12:33 PM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 05:21 PM


All times are GMT -5. The time now is 02:44 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration