Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Unix&Linux>>Bash script does not work!

Bash script does not work!

raheelm
04-10-2005, 01:29 AM
This has to be the simplest question yet:
I have a file called gotoDocuments which contains

#! /bin/bash
cd ~/Documents

I did chmod +x on it. When I execute it, there is no directory change. What I am doing wrong?
Thanks.

hayne
04-10-2005, 02:36 AM
There is nothing wrong with your script.
What is wrong is your expectations of what a script should do.
A shell script runs in a new instance of the shell - i.e. a sub-shell. When you change directory in your script, you are only changing the current directory of that sub-shell. And when the script is finished, the sub-shell exits and is no more.

If you want to change the environment of the current shell, you need to use the "source" command to run the script. In bash, the "source" command is the 'dot' operator (.).

E.g.:

. gotoDocuments


There is no need for a script that you will be sourcing (like above) to be executable.

cradom
04-10-2005, 11:21 AM
For something like that, wouldn't it be easier to make it an alias in your .bashrc or .bash_profile file?


 

TOP

Windows Server Outsell
Unix Signals And C++ E

For more info

Unix Signals And C++ E
Windows Server Outsell
ssh setup for password
Bash script does not w
esc code 
ARD send unix command 
question about binarie
Scanning mail 
Issuing multiple comma
How do I install Linux

News Archive

/etc/hosts? 
Manually Start a Start
mounting missed hard d
Using Netinfo in Singl
darwin/bsd login probl
system_profiler and fi
Send mail from script 
mounting a drive 
OS X disk first aid ha
system.log shows steal

Related stories:

esc code
ARD send unix command question
question about binaries
installing Libusb
Issuing multiple commands through SSH
ssh setup for passwordless login
quoting string with single quotes inside?

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics