C-shell Script to Bash Script?

C-shell Script to Bash Script?

Post by qquit » Fri, 03 Aug 2007 05:56:55


Dear Everyone:

I used to use the following three lines of C-shell script

foreach file (`ls -1 name.list.txt`)
a.out $file
end

to do a loop. The 1st line lists the content in the file named
"name.list.txt", and in the 2nd line, an excutable file, a.out, takes
each listed item as an argument, and the 3rd line ends the loop.

How would you convert the above three lines to BAsh (Bourne Again
shell) script to be used on a Mac?

Thank you for reading and replying!

--Roland
 
 
 

C-shell Script to Bash Script?

Post by Chris F.A. » Fri, 03 Aug 2007 06:25:51


Where does it list the contents of name.list.txt? It just lists
the file (and ls is unnecessary)


To do the same as that script:

for file in name.list.txt
do
a.out
done

If you want to read the contents of name.list.txt, use:

while IFS= read -r file
do
a.out "$file"
done < name.list.txt

--
Chris F.A. Johnson, author | < http://www.yqcomputer.com/ >
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence

 
 
 

C-shell Script to Bash Script?

Post by qquit » Fri, 03 Aug 2007 06:49:41

Chris: Just tried what you suggested, and it works. Thanks a lot. ---
Roland
 
 
 

C-shell Script to Bash Script?

Post by Dave Seama » Fri, 03 Aug 2007 07:29:23


By the way, csh is on the Mac. If you have a csh script that actually
works, you don't need to convert anything. All you need is an
appropriate shebang line:

#!/bin/csh
foreach file (whatever you actually want here)
a.out "$file"
end



--
Dave Seaman
*** Arguments in Mumia Abu-Jamal Case heard May 17
U.S. Court of Appeals, Third Circuit
< http://www.yqcomputer.com/ ;
 
 
 

C-shell Script to Bash Script?

Post by thepixelfr » Sat, 04 Aug 2007 03:03:24

On 2007-08-01 13:56:55 -0700, qquito < XXXX@XXXXX.COM > said:


for i in `cat name.list.txt` ; do
a.out $i
done

make sure you are using the back tick on the same key as the tilde ~
key to surround the `cat namelist.txt`.
--

thepixelfreak
 
 
 

C-shell Script to Bash Script?

Post by John Taylo » Sat, 04 Aug 2007 04:50:45


That depends what locale your keyboard is.

On my keyboard ~ is on the same key as # down near the enter key
back-tick is with and top left, next to 1

Or do Mac keyboards not have a locale ?

Regards
JohnT
 
 
 

C-shell Script to Bash Script?

Post by William Mi » Sat, 04 Aug 2007 05:19:33

qquito < XXXX@XXXXX.COM > writes:


A literal translation of what you have is

for file in `ls -l name.list.txt` ; do a.out $file ; done

What you seem to have in mind:

for name in `cat name.list.txt` ; do a.out $name ; done

--
Bill Mitchell
Dept of Mathematics, The University of Florida
PO Box 118105, Gainesville, FL 32611--8105
XXXX@XXXXX.COM (352) 392-0281 x284