'How to create functions for navigating paths in unix (in tch shell)

How to create functions for navigating paths in unix (in tch shell), below I have created is not working:

#!/bin/sh
proto(){
if [ $# == 2 ]
        then
                `cd /zz/apxxcd/$1/$2/aaaa/caaa/`
        else
                `cd /Vscm/nnnn/$1/saseng/aaa/`
fi
}

proto


Solution 1:[1]

Two errors:

  1. Your $# has the bad comparision operator, it should be -eq not ==
  2. You don't give parameter to proto function when you call it.
    Change proto line to proto $*
#!/bin/sh
proto(){
if [ $# -eq 2 ]
        then
                `cd /zz/apxxcd/$1/$2/aaaa/caaa/`
        else
                `cd /Vscm/nnnn/$1/saseng/aaa/`
fi
}

proto $*

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mathieu