> Try Tcsh then, if you like c syntax.
...and don't mind your shell being horribly broken:
> 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 :
>>>> for i in `seq 1 50`;
>> echo $i
>>>> 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,
which, in spite of its name, only really assumes you already know how to
You're really better off sticking with a modern sh derivative like bash or
zsh rather than using something like csh.
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!