How to write shell scripts in Sun Solaris?

11,867

Solution 1

  • create script file, first row beginning with this: #!/bin/sh -
  • add script body (echo Hello world) on following lines after that.
  • make script executable (chmod u+x scriptfile)
  • either put scriptfile somewhere in your path, or invoke it by its pathname.

./scriptfile is the relative pathname if your current directory is where you put the script.

Solution 2

It is not very different from writing a shell script in Linux. Some pitfalls:

  • Relying on GNU tools, but not installed (sed, awk, grep -r etc.)
  • Path names (if you use bash, prefix all your scripts with #!/usr/bin/env bash

I suggest you to read http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html.

Share:
11,867

Related videos on Youtube

coderlearner
Author by

coderlearner

Updated on September 17, 2022

Comments

  • coderlearner
    coderlearner over 1 year

    I am new to Unix shell scripting. So can anybody help me?

    How to write shell scripts in Sun Solaris? How to run/execute the script?

    Please post in detail.

    • coderlearner
      coderlearner over 13 years
      i have very good skills in C++ language
    • chunkyb2002
      chunkyb2002 over 13 years
      Shell scripting is very different to c++ so the learning curve might be quite steep. Check out freeos.com/guides/lsst its aimed at Linux OS's but the principles are largely the same.
    • user9517
      user9517 over 13 years
      This is outside the scope of server fault. A common shell to script in is bash - you can find an introduction to bash scripting here