Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Bash Script works in CentOS, fails in Debian

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
cmorris14
Posts: 4
Joined: 2014-04-21 18:47

Bash Script works in CentOS, fails in Debian

#1 Post by cmorris14 »

I have a portion of a script that works fine when I'm using it in CentOS, but fails in Debian. The script is below.

Code: Select all

#!/bin/csh -f
...
foreach i (`cat /home/user/systems.txt`)
	$ping $i > /dev/null
	if $status != 0  continue
	/bin/echo $i >> /home/user/lservers
end
...
The error is - Syntax error: "(" unexpected

What is the problem?

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Bash Script works in CentOS, fails in Debian

#2 Post by dasein »

cmorris14 wrote:What is the problem?
A potentially much more informative question is: what have you been able to rule out, based on the research you've done so far?

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Bash Script works in CentOS, fails in Debian

#3 Post by tomazzi »

cmorris14:
This is a csh script which deos not work under bash.
Perhaps more verbose error message would be "foreach does not name a function"... :)

In bash You should use:
for var in ...

Regards.
Odi profanum vulgus

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Bash Script works in CentOS, fails in Debian

#4 Post by dasein »

Another homework problem successfully answered.

User avatar
aicardi
Posts: 388
Joined: 2009-11-18 01:30
Location: Chicago

Re: Bash Script works in CentOS, fails in Debian

#5 Post by aicardi »

dasein wrote:Another homework problem successfully answered.
+1 lol
Jessie/Xfce

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Bash Script works in CentOS, fails in Debian

#6 Post by tomazzi »

aicardi wrote:
dasein wrote:Another homework problem successfully answered.
+1 lol
Yeah, LOL, spamming threads can be funny...
..and the post counter is rising... so You two may feel better (a more important persons), but You know what? - peoples are reading such threads and they are taking the conclusions...

Regards.
Odi profanum vulgus

runfrodorun
Posts: 202
Joined: 2013-06-19 05:09

Re: Bash Script works in CentOS, fails in Debian

#7 Post by runfrodorun »

But better yet, your initial answer is wrong.

#!/bin/csh

specifies that the script is to be run with csh regardless of the interactive shell that the user has chosen. A simple google search and a brief test will show this... and the people reading this thread will see you being incorrect and needlessly confrontational.
Much opinionated.
Some abrasive.
No systemd.
Wow.

tomazzi
Posts: 730
Joined: 2013-08-02 21:33

Re: Bash Script works in CentOS, fails in Debian

#8 Post by tomazzi »

ooops, somehow I've missed the response in this thread...
runfrodorun wrote:But better yet, your initial answer is wrong.

#!/bin/csh

specifies that the script is to be run with csh regardless of the interactive shell that the user has chosen. A simple google search and a brief test will show this... and the people reading this thread will see you being incorrect and needlessly confrontational.
It was not clear (at the moment when I've written a reply) whether cmorris14 is going to use original file with shebang or not. The error message shows, that He's not using shebang, and therefore my previous reply is valid. So It's also obvious, that I think that Your reply is nothing more than trolling.

Regards.
Odi profanum vulgus

Post Reply