LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-27-2007, 08:54 AM   #1
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 207Reputation: 207Reputation: 207
C Shell, while loop in interactive mode?


Hi, How do I write a while loop in an interactive C shell? When I write out

while (1); echo "potato"; end

I am prompted on another line for the body of the loop.

Thanks!
 
Old 06-27-2007, 09:47 AM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,003
Blog Entries: 5

Rep: Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782
The ";" is relevant to shell meaning "execute next command synchronously". You are not however, just in the the shell itself once you issue "while" you are in the loop so you have to use the syntax understood by while itself. You are not asking it to execute another command but rather to continue with the "while" command.

So on command line you'd have to type it as 3 lines:
Code:
while (1)
echo "potato"
end
If you're creating a script you can put this within the script.
 
Old 06-27-2007, 10:52 AM   #3
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 207Reputation: 207Reputation: 207
well thats no good; you can do that sort of thing in bash, why not csh?
 
Old 06-27-2007, 11:39 AM   #4
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,003
Blog Entries: 5

Rep: Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782
Because csh' man page specifically says "while" and "end" must appear on lines by themselves.

A better question is why would anyone want to use csh when bash, posix sh and ksh are in the world.
 
Old 06-27-2007, 12:46 PM   #5
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 207Reputation: 207Reputation: 207
Quote:
A better question is why would anyone want to use csh when bash, posix sh and ksh are in the world.
Haha, indeed. It's the default at my company and I haven't yet figured out how to make it bash or zsh when I login. Seems like a quick google search would answer me that, though.
 
Old 06-27-2007, 12:54 PM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
If you're allowed to use "chsh" (i.e. "change shell"), that'll do it.
 
Old 06-27-2007, 02:16 PM   #7
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,003
Blog Entries: 5

Rep: Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782
If you can't do a usermod or moduser to change the shell (which you can't if you don't have root access) you can always start it as a subshell just by typing the name of the new shell at the command line:
bash

If you don't want it to be a subshell you could just type:
exec bash

That way when you exit bash it will log you out because csh won't be there any more.

You could add the "exec bash" to your $HOME/.login file to make it do it automatically when you login with csh.

P.S. You can make your scripts run as bash by adding the interpreter line as the first line of the script:
#!/bin/bash

That way even if you have coworkers that run the scripts you create from their own csh logins the script itself will invoke bash before executing the commands that follow.

Last edited by MensaWater; 06-27-2007 at 02:18 PM.
 
  


Reply

Tags
csh, interactive, while


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
interactive and non-interactive shell linuxjamil Programming 3 09-03-2006 08:42 PM
bash script works when interactive, endless loop when started via cron dguy Linux - General 5 04-10-2006 11:39 AM
FC2 can not start alone (in non-interactive mode) unsem Fedora 2 11-09-2004 12:59 AM
permanant interactive mode stand Linux - General 1 04-19-2004 05:21 AM
not able to get into interactive mode when linux is booting up? anekkan Linux - Newbie 1 09-06-2003 10:06 PM


All times are GMT -5. The time now is 09:11 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration