custom command

hi
I am trying to make my own commands in my linux.I thought a command for changing directories will be easy.

I made a simple file amd made the entries

#!/bin/bash
cd /opt/mydir

I then made the file executable and then moved it to /usr/bin.

But when i type the script name nothing happens i am still in the same directory.
please help

Imagine what happens when you run that program.

1) The shell fork off a separate process.
2) That process does exec("/usr/bin/mycommand");
3) That process loads your code, and does cd /opt/mydir
4) It then quits
5) Your shell is still sitting there where it started since each program has its own current directory

cd has to happen inside the shell to work in your shell, nothing else can do it.

Since you're using bash, just put this in your ~/.bashrc instead:

function myfunction
{
        cd /opt/mydir
}

tanx buddy :b:

well i never really thought about the internals of the shell....tanx for the info