This is a discussion on C-shell Script to Bash Script? within the Linux General forums, part of the Linux Forums category; Dear Everyone: I used to use the following three lines of C-shell script foreach file (`ls -1 name.list....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
On 2007-08-01, qquito wrote:
> 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", Where does it list the contents of name.list.txt? It just lists the file (and ls is unnecessary) > 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? 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://cfaj.freeshell.org> Shell Scripting Recipes: | My code in this post, if any, A Problem-Solution Approach | is released under the 2005, Apress | GNU General Public Licence |
|
|||
|
Chris: Just tried what you suggested, and it works. Thanks a lot. ---
Roland On Aug 1, 5:25 pm, "Chris F.A. Johnson" <cfajohn...@gmail.com> wrote: > > 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 |
|
|||
|
On Wed, 1 Aug 2007 17:25:51 -0400, Chris F.A. Johnson wrote:
> On 2007-08-01, qquito wrote: >> 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", > Where does it list the contents of name.list.txt? It just lists > the file (and ls is unnecessary) >> 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? > 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 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 Oral Arguments in Mumia Abu-Jamal Case heard May 17 U.S. Court of Appeals, Third Circuit <http://www.abu-jamal-news.com/> |
|
|||
|
On 2007-08-01 13:56:55 -0700, qquito <qquito@hotmail.com> said:
> 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 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 |
|
|||
|
thepixelfreak wrote:
> > make sure you are using the back tick on the same key as the tilde ~ key > to surround the `cat namelist.txt`. 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 |
|
|||
|
qquito <qquito@hotmail.com> writes:
> 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 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 mitchell@math.ufl.edu (352) 392-0281 x284 |