Indentation help

Hi
I have coded 300 line script.Its not indented properly.i am not good at indentation.
I would appreciate your help on this.
i want to use a 4 space indentataion.Hence if i "set tabstop=4" and use tabs for coding and if some one else open
this script in their system it looks unindented since default value for tab is 8.
I have tried beautify ruby script but ruby script fails.
I would appreciated help
1)Any utility to beautify by apply indentation
2)Any documenation for indentation for korn shells.
3)Any standards for identation and its procedure for very long scripts.

What does your editor of choice do to tabs? What is your editor, for that matter? Tabs should still be there even if differently sized unless your editor does something weird.

try 'setterm -regtabs 4' to make a console have tabs at 4 spaces. In my case I had to force it with 'TERM=linux setterm -regtabs 4'

The only way to get consistent indentation is to use paces, not tabs.

My editor (GNU emacs) handles indentation nicely for most langauges, and it's customizable.

I have downloaded GNU emacs.
I put some code on editor on my windows machine.

I pressed cntl+alt+\

It did not indent my code.
Can please help how the emac will automatically indent all my 300 script shell.

At the top of the buffer, press Ctrl+<space>, move to the bottom of the buffer and press cntl+alt+\

Sir,

I am new to emacs.
Can you please explain what is buffer.Is it the white screen that comes up when i start emacs on windows

A buffer is the area that stores your file.

I could have said, "Go to the top of your file."

(You can have many buffers open at once. I typically have 50.)

when i press Ctrl+<space>, move to the bottom of the buffer and press cntl+alt+\

This moves all the lines to left starting at position 0.

I want indentation to be like the follwoing

          if (command)
          then
              echo "hello world"
          fi 

Same case for while loops and other syntaxes

Are you in shell-script-mode?

Try M-x (usually Alt-X) shell-script-mode, then do the above.

Change mode to M-x and then moved to the top of buffer pressed
ctrl+space

then moved to the bottom of buffer and pressed ctrl+alt+\

It did not do anything.
All the lines are still starting from the left most side without any indentation

Is it really possible to get all the identation with emac as how a professional shellscripter does indentation?

Help is highly appreciated.

M-x is not a mode, it allows you to enter a command. After pressing M-x, enter the command:

shell-script-mode

to enter shell-script mode.

Yes, I do it all the time.

Sir,

I did
1)Alt+x
2)shell-script-mode
3)ctrl+space on top of buffer
4)at bottom of buffer ctrl+alt+\

this did change the code to right by 4 spaces

    help () {
    print $USAGE
    echo "-h see this help"
    echo "-c input file (required)"
    exit 0 
    }

I would like emac to do as following

    help () {
        print $USAGE
        echo "-h see this help"
        echo "-c Config File (required)"
        exit 0 
    }

This kind of indentation should be done.
And for nested if statements then it should do indentation for nested if as how it is done by a shell scripter.

if condition
then
    ....
        if condition
        then
            .......
        fi
fi
        

Appreciate all your help.