DIGIT-ARC read-only archive · snapshot: July 23, 2026

A tiny bash issue

7 posts · originally from https://geek.digit.in/community/threads/a-tiny-bash-issue.66588/

QwertyManiac
QwertyManiac Original post #1
Aug 26, 2007 at 6:18 PM
Can someone tell me why my little script below (To switch the directory via BASH) does nothing on execution?

Code:
#!/bin/bash
cd /home/qwerty/Programs/C
#abc.sh
Here's my output: (Actually, its NOTHING)

Code:
qwerty@qwerty-workstation:~$ ./abc.sh 
qwerty@qwerty-workstation:~$
I got no clue at all.

And before someone mentions, its chmod +x'ed alright.
mediator
Aug 26, 2007 at 6:28 PM
The script is alright and the control return to the original directory after the execution of 'cd' command. That means that the directory is switched as desired and after the execution of the script it returns to the original directory!

To verify it, create some file(s) in '/home/qwerty/Programs/C' and then use some other command with it! e.g
Code:
#!/bin/bash
cd /home/qwerty/Programs/C
ls

This will switch the directory first, show the contents of that directory and then return the control to the original directory!
QwertyManiac
Aug 26, 2007 at 6:43 PM
Thanks mediator, I understand it now, but ..

Can I switch control to another directory permanently? So that my current terminal directory gets changed to that? That was my actual aim.

Edit: I got my silly solution by creating an alias command, but I'd still like to know the way (if possible) to change the current directory via a script :)
Sykora
Sykora #4
Aug 26, 2007 at 7:04 PM
Try
Code:
$ source abc.sh

Instead of

Code:
$ ./abc.sh
QwertyManiac
Aug 26, 2007 at 7:14 PM
Oh, didn't know about that command before. Problem solved, thanks mediator and Sykora.
praka123
Aug 27, 2007 at 7:49 AM
Infact a "." does the job too reg source command:

*learnlinux.tsf.org.za/courses/build/shell-scripting/ch10s02.html
mediator
Aug 27, 2007 at 11:16 AM
^Yup, " . abc.sh " also does the job!