Bluehost.com Web Hosting $6.95

C-shell Script to Bash Script?

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


Go Back   Usenet Forums > Linux Forums > Linux General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-01-2007
qquito
 
Posts: n/a
Default C-shell Script to Bash Script?

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

Reply With Quote
  #2 (permalink)  
Old 08-01-2007
Chris F.A. Johnson
 
Posts: n/a
Default Re: C-shell Script to Bash Script?

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
Reply With Quote
  #3 (permalink)  
Old 08-01-2007
qquito
 
Posts: n/a
Default Re: C-shell Script to Bash Script?

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


Reply With Quote
  #4 (permalink)  
Old 08-02-2007
Dave Seaman
 
Posts: n/a
Default Re: C-shell Script to Bash Script?

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/>
Reply With Quote
  #5 (permalink)  
Old 08-02-2007
thepixelfreak
 
Posts: n/a
Default Re: C-shell Script to Bash Script?

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

Reply With Quote
  #6 (permalink)  
Old 08-02-2007
John Taylor
 
Posts: n/a
Default Re: C-shell Script to Bash Script?

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
Reply With Quote
  #7 (permalink)  
Old 08-02-2007
William Mitchell
 
Posts: n/a
Default Re: C-shell Script to Bash Script?

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:39 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0