I want to learn shell scripting and I will use solaris in my work. Is there any difference between shell scripts on linux and shell scripts on solaris?
2 Answers
The difference is not between Linux and Solaris, the difference is between which shell you are using on each: sh, csh, ksh, zsh, bash etc.
When you write a shell script you should always start it with a shebang indicating what shell the script is written for. For example
#!/bin/bash
or
#!/bin/csh
Note shebang also works for scripting in non-shell languages:
#!/usr/bin/perl
#!/usr/bin/python
The bash shell is now commonly available nearly everywhere, and I suggest that's the one you learn if it's available on you Solaris system.
/bin/sh is the POSIX shell and you should learn that, and the differences between it and bash.
ksh is an improvement over sh, as is zsh (but zsh claims it "is a shell designed for interactive use")
csh is considered evil
These days bash and sh are the ones to learn.
1 Comment
/bin/sh is the POSIX shell... Be careful. Because Linux tends to entirely conflate sh and bash - sh may even be softlinked directly to bash. Solaris doesn't do that. Many are the Linux "sh" scripts that fail on Solaris because of bashisms.thank you all. What I understood from your replies that I have to learn the bash shell which is compatible with linux and solaris.