Re: script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 22, 2006 at 12:20:39PM +0530, Kaushal Shriyan wrote:
> #!/bin/bash
> va=`cut -d"/" -f2 out`
> #cat out > va
> echo $va
> cd $va
> 
> The issue is that it doesnot cd to the directory after running the script 

The script is run in a subshell and can not affect your running shell's
working directory (unless you invoke it by ". script-filename", in which case
you are running its commands in the context of your running shell).

Observe:

    $ cat foo.sh
    #!/bin/sh
    cd /tmp

Just trying to execute the script:

    $ ./foo.sh
    $ pwd
    /home/kayvan

But, using "." to execute the commands in the current shell:

    $ . ./foo.sh
    $ pwd
    /tmp

Another solution if you want this to affect your shell is to use the "alias"
command or shell functions.

Read "man bash" and http://www.tldp.net/HOWTO/Bash-Prog-Intro-HOWTO.html

Best regards,

			---Kayvan
-- 
Kayvan A. Sylvan          | Proud husband of       | Father to my kids:
Sylvan Associates, Inc.   | Laura Isabella Sylvan, | Katherine Yelena (8/8/89)
http://sylvan.com/~kayvan | my beautiful Queen.    | Robin Gregory (2/28/92)


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux