luker_luker wrote:
> Try Tcsh then, if you like c syntax.
...and don't mind your shell being horribly broken:
http://www.grymoire.com/Unix/CshTop10.txt
> On Thu, Feb 17, 2011 at 11:53 AM, Conor Wynne <mariconor at gmail.com> wrote:
>>> Hi all,
>>>> When scripting in bash, and using C style syntax, example
>>>> for (i=0;i<=50;i++)
>>>> do I have to declare the variable(s) before hand?
>>>> Compared to :
>>>> #!/bin/bash
>>>> for i in `seq 1 50`;
>> do
>> echo $i
>> done
>>>> Just wondering.. as I'm more familiar with C than anything else.
No, you don't have to declare variables. They're declared by their
first use, as is being down in the first line of the for-loop. You
won't get an error if you try to dereference a variable (as is happening
in the echo statement) that hasn't already been defined/declared - it'll
dereference to, essentially, nothing: an empty string.
I'd advise you to have a read through the Advanced Bash Scripting Guide[1],
which, in spite of its name, only really assumes you already know how to
program.
You're really better off sticking with a modern sh derivative like bash or
zsh rather than using something like csh.
K.
[1] http://tldp.org/LDP/abs/html/
K.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!