Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

how to use cd command for change directory in zenity, my simple script like this

#!/bin/bash    
a=`zenity --entry --entry-text="input directory name"`
cd $a

but, when cd [The cd (ChangeDirectory) command will change from your current directory to any directory you specify] command change to rmdir/mkdir, its work perfect..

please help me..

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The cd is working, but it only affects your script's process, not the shell from which you ran the script. Several approaches have been used to work around this in the past, but the best one right now is probably to use a shell function instead of a separate script, since a shell function will run within your original shell instead of a separate process.

This would be done in your ~/.profile:

cdprompt()
{
    cd $(zenity --entry --entry-text="input directory name")
}

If you then start a new shell and run cdprompt, it should show the zenity prompt and change to the directory you enter as expected.

If you really want the commands to live in a separate file, another option is to source the file instead of running it:

source newdir.sh

or

. newdir.sh

This tells bash to run the commands in the file within your current process rather than starting a new one. It's normally used to load configuration rather than run programs, but it should work for this as well.

share|improve this answer
    
really thanks for your answer, but unfortunately..its still not working.. –  haritsmp Jun 8 '13 at 5:25
    
What problem are you having with it? I tested it on my system before posting, and it did what it sounds like you want to do. –  Paul Jun 8 '13 at 5:28
    
i'll capture it.. skydrive.live.com/… –  haritsmp Jun 8 '13 at 5:50
    
Don't create a script file containing this. Just add it to your existing ~/.profile or ~/.bashrc files and run "cdprompt" from your login prompt, not from inside of a script. –  Paul Jun 8 '13 at 6:47
    
I thought of another solution that might work more easily for you and added it to my answer. –  Paul Jun 8 '13 at 14:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.