An unexpected result with a bash script

Booting, installing, newbie
Post Reply
Message
Author
User avatar
LNSmith
Posts: 126
Joined: Thu 28 Mar 2013, 14:24
Location: A little north fr. Sydney, AU

An unexpected result with a bash script

#1 Post by LNSmith »

I wish to quickly switch between directories.

I made a script:
#!/bin/sh
# script to make /mnt/sda1/ ... /text the working directory
echo switching to new directory
cd /mnt/sda1/Law/bNgo/Transcript/text
echo -n working directory is:
pwd
I run the script and see:
switching to new directory
working directory is:/mnt/sda1/Law/bNgo/Transcript/text

I'm there! The script has switched to the new directory! Great!
Then, when I use the command: pwd (in LXTerminal) I see:
/root
Somehow - after running the script - the working directory reverts to the directory calling the script. WHAT! SHOCK! BOTHER. DRAT. boy-OH-boy.
Lots of little gotcha's in here.

Can anyone tell me how to make bash REMAIN in the directory the script transferred to? Please? Clearly bash remember 'where' and (after running) it goes back to 'where'. Calling the script from '/root/ returns to /root. Calling from /home returns to /home. Oh-boy!

Leslie

Maybe I can make a variable to stay in the root directory and trick bash so it thinks I'm in the text directory. Also, I want to keep my work in /mntsda1. I don't want to do my work "under" /root. (But maybe someone will tell the that's the best idea ...)

phat7
Posts: 179
Joined: Fri 05 Jun 2015, 08:54

#2 Post by phat7 »

Leslie, you asked this question 3 weeks ago in cd command in a script gives an unexpected result. You received an answer. You never replied.

User avatar
LNSmith
Posts: 126
Joined: Thu 28 Mar 2013, 14:24
Location: A little north fr. Sydney, AU

An unexpected result with a bash script. (solved)

#3 Post by LNSmith »

Hello phat7

To me:
You received an answer. You never replied.
Yes, and thank you for replying.
Sometimes I am confused between things I have done and things I intend to do. Your solution works! I'm doubly indebted to you. Leslie

Post Reply