Find the answer to your Linux question:
Results 1 to 2 of 2
Hello , I am new to use z-shell .I am trying to understand a script written in Z-Shell .Can anybody plz tell me what is the meaning of command "cd ...
  1. #1
    Just Joined!
    Join Date
    Nov 2006
    Posts
    2

    Zshell

    Hello ,
    I am new to use z-shell .I am trying to understand a script written in Z-Shell .Can anybody plz tell me what is the meaning of command "cd $0:h"

  2. #2
    Just Joined!
    Join Date
    Aug 2007
    Posts
    37
    The short answer is that it changes the current directory to the directory in which the script resides.

    $0 is a positional parameter that, in this context, expands to the path of the script which is currently running.

    :h is one of a pair of modifiers (:h head, and :t tail).

    If the path to the script that you are running is /home/shwetank_gupta/bin/myscript.sh then :t is the 'tail' of the path: myscript.sh, and :h is the rest of the path i.e. /home/shwetank_gupta/bin.

    So "cd $0:h" would change directory to /home/shwetank_gupta/bin.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...