# Lang for OS interaction



## Seeker (Feb 2, 2010)

So...
Time has come, for me, to put some automated tasks in a script, in order to more efficiently control and interact generally with my OS -> _THE FreeBSD_

sh, csh, tcsh, or PHP (in which I code web applications, for very long and know it upside down and do _it_ with OO approach and generally it is in my finger).

root is by default bestowed by csh shell and recommended to switch to tcsh.
Then again, why all /etc/rc.d scripts are written in sh shell language and not in "superior" [t]csh shell?

Hell, should I just skip learning and stick to what I know and do all with PHP?

PS: What extension of files do you recommend for PHP CLI scripts?


----------



## graudeejs (Feb 2, 2010)

[t]csh is not is not superior, in fact it's inferior....
they are root shell by default because.... try using sh for few days, and you'll see.

I'd love to see mksh or something of msh family as default shell

Learning sh will give you many advantages with many common problems


----------



## aragon (Feb 2, 2010)

I much prefer Bourne shell for system scripts, but in certain instances it can just be too slow for certain tasks.  My advice is stick to Bourne as much as possible, but use PHP or Python where Bourne is inappropriate.


----------



## Alt (Feb 2, 2010)

My advice is never use brourne shell xD Use sh and perl for system scripts. For really close system work - C.


----------



## graudeejs (Feb 2, 2010)

brourne shell == sh
lol


----------



## DutchDaemon (Feb 2, 2010)

This might get confusing very quickly. Seeker, you're posting this in "Userland Programming & *Scripting*", yet your topic is "Lang for OS *interaction*".

Is your question about scripting or interacting? As far as _shells_ (in the strict sense) are concerned: for shell *scripting*, most people will advise you to stick with '*sh*'. For shell *interaction*, most people will tell you *not* to use '*sh*'.

I don't really know what "Lang(uage) for OS interaction" is .. did you mean "Language for scripting"? Then you can look at perl, python, etc. etc.


----------



## Seeker (Feb 2, 2010)

I see..., so tcsh and csh, are intended to ease human, with interacting with OS.

And sh is for scripting automated task as is "stable" and well tested.
How complex is sh anyway. Closer to JavaScript or PHP ( LOL! web dev  )



			
				DutchDaemon said:
			
		

> This might get confusing very quickly. Seeker, you're posting this in "Userland Programming & *Scripting*", yet your topic is "Lang for OS *interaction*".
> 
> Is your question about scripting or interacting? As far as _shells_ (in the strict sense) are concerned: for shell *scripting*, most people will advise you to stick with '*sh*'. For shell *interaction*, most people will tell you *not* to use '*sh*'.
> 
> I don't really know what "Lang(uage) for OS interaction" is .. did you mean "Language for scripting"? Then you can look at perl, python, etc. etc.



Duh! You have now totally confused me.
Scripting..., which is automation of task of this type

How do you define shell interaction, anyway?! I would say I interact wit shell by mouse and keyboard.
So when I do scripting, then that script interacts with shell thus doing some automated tasks _to_ OS

So I guess it would be / mean:
Lang for writing scripts that will do OS interaction


----------



## aragon (Feb 2, 2010)

Seeker said:
			
		

> How complex is sh anyway. Closer to JavaScript or PHP ( LOL! web dev  )


Pretty simple, just weird.  A lot of operations are just programs executing and the interpreter responding to exit codes.  The more you use it the more you begin to "get it", so get started. 

I'd say it's nothing like PHP or JavaScript.


----------



## aragon (Feb 2, 2010)

killasmurf86 said:
			
		

> bourne shell == sh


Yup.

BASH = Bourne _Again_ SHell


----------



## Seeker (Feb 2, 2010)

aragon said:
			
		

> ...
> I'd say it's nothing like PHP or JavaScript.


Of course it's nothing like PHP or JavaScript.
I wanted reference to *complexity*.
PHP is *far more* complex then JavaScript.
So is sh *complex* like JS or PHP?

Can I/should do all that in PHP, instead _"wasting time"_ learning sh? :stud


----------



## aragon (Feb 2, 2010)

Seeker said:
			
		

> Of course it's nothing like PHP or JavaScript.
> I wanted reference to *complexity*.
> PHP is *far more* complex then JavaScript.
> So is sh *complex* like JS or PHP?


It's a very simple language compared to both of those.  Then again, I think JavaScript is more complex than PHP, so who knows what you'll think of Bourne.   Try it.




			
				Seeker said:
			
		

> Can I/should do all that in PHP, instead _"wasting time"_ learning sh? :stud


All FreeBSD userland scripts are written in Bourne.  It will never be a waste learning it.


----------



## Seeker (Feb 2, 2010)

You think wrong... PHP is more complex then JavaScript.

Ok guys, just spit out a _best_ *sh* related book.


----------



## aragon (Feb 2, 2010)

Seeker said:
			
		

> You think wrong... PHP is more complex then JavaScript.


Nope, I think different.



			
				Seeker said:
			
		

> Ok guys, just spit out a _best_ *sh* related book.


sh(1), google, and all the FreeBSD system scripts.


----------



## graudeejs (Feb 2, 2010)

I learned sh from 
http://www.grymoire.com/Unix/Sh.html


----------



## Seeker (Feb 2, 2010)

killasmurf86 said:
			
		

> I learned sh from
> http://www.grymoire.com/Unix/Sh.html


How much time have you spent on it?


----------



## dennylin93 (Feb 3, 2010)

I think the easiest way to learn sh() is by opening some simple scripts and looking up the syntax in the man page.


----------



## SirDice (Feb 3, 2010)

killasmurf86 said:
			
		

> I learned sh from
> http://www.grymoire.com/Unix/Sh.html



I use that one quite a lot for reference :e


----------



## graudeejs (Feb 3, 2010)

Seeker said:
			
		

> How much time have you spent on it?



few days.... then I started writing some script, which later turned out to be multimedia/playd


----------



## Ruler2112 (Feb 3, 2010)

I find that I need to use bash for some scripts, just because of the ability to direct STDOUT and STDERR to different places; bash has the mechanism with 1> and 2>   I tend to lean toward perl whenever I need to do something, but that's probably because I'm very comfortable with it and have used it extensively the past couple years writing applications with a web front-end.


----------



## SirDice (Feb 3, 2010)

Ruler2112 said:
			
		

> I find that I need to use bash for some scripts, just because of the ability to direct STDOUT and STDERR to different places; bash has the mechanism with 1> and 2>


No need for bash, the bourne shell can do that too. Stop calling /bin/sh bash. It's not (except on linux).

For reference: http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ :e


----------



## Seeker (Feb 3, 2010)

SirDice said:
			
		

> No need for bash, the bourne shell can do that too. Stop calling /bin/sh bash. It's not (except on linux).
> 
> For reference: http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ :e


Date: 6 Oct 1996 14:03:18 GMT

Come on. That info is very old.
All shells have been improved, over last 14 years


----------



## SirDice (Feb 3, 2010)

Seeker said:
			
		

> Date: 6 Oct 1996 14:03:18 GMT
> 
> Come on. That info is very old.
> All shells have been improved, over last 14 years



Not on the most basic stuff. The new versions of these shells still need to be able to run 15 year old code


----------



## Ruler2112 (Feb 3, 2010)

SirDice said:
			
		

> No need for bash, the bourne shell can do that too. Stop calling /bin/sh bash. It's not (except on linux).
> 
> For reference: http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ :e



That's interesting... I remember trying it for something (I forget what) a few weeks ago and 2> simply would not work.  I ended up installing bash from ports solely for that purpose.  

/bin/sh = bourne shell
/usr/local/bin/bash = bourne again shell


----------



## avilla@ (Feb 3, 2010)

Seeker said:
			
		

> PHP is *far more* complex then JavaScript.
> So is sh *complex* like JS or PHP?



this is just like comparing bananas to bicycles...


----------



## Seeker (Feb 4, 2010)

It is not as there is no direct comparision of features, BUT comparision of amount of syntax to learn (ie: complexity)


----------



## lesha (Feb 17, 2010)

[t]csh are more efficiently for doing administrative works:
       more history buffer space;
       more features...
etc.


----------



## gnemmi (Feb 17, 2010)

_really_ personal opinion: sh or perl depending on which one has the language features that better suits the given task.


----------

