LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   a script (https://www.linuxquestions.org/questions/linux-newbie-8/a-script-859015/)

apurak 01-27-2011 07:50 AM

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?

sycamorex 01-27-2011 08:00 AM

Quote:

Originally Posted by apurak (Post 4239442)
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

apurak 01-27-2011 08:44 AM

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

i92guboj 01-27-2011 08:49 AM

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.

sycamorex 01-27-2011 08:53 AM

Quote:

Originally Posted by apurak (Post 4239489)
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


apurak 01-27-2011 09:02 AM

is this correct:
ls * | xargs foo2bar

schneidz 01-27-2011 09:09 AM

^ 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.

i92guboj 01-27-2011 09:17 AM

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.

onebuck 01-27-2011 03:36 PM

Hi,

Welcome to LQ!

Quote:

Originally Posted by apurak (Post 4239442)
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!

sycamorex 01-27-2011 06:39 PM

@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:)

papagu 04-07-2012 03:40 AM

the script itself
 
Quote:

Originally Posted by apurak (Post 4239442)
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?


All times are GMT -5. The time now is 04:32 AM.