A tiny bash issue

Status
Not open for further replies.

QwertyManiac

Commander in Chief
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

Technomancer
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!
 
OP
QwertyManiac

QwertyManiac

Commander in Chief
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 :)
 
Last edited:

praka123

left this forum longback
Infact a "." does the job too reg source command:

*learnlinux.tsf.org.za/courses/build/shell-scripting/ch10s02.html
 
Status
Not open for further replies.
Top Bottom