BASH Script Change Directory
This is going to sound like a really dumb question, but is there any way to have BASH leave the user in the current directory from the script, rather than returning them to the directory they were in when the script was called?
For example... the user is in their home directory and call the following BASH script:
#!/bin/bash
cd /var/log
lsWhen the script exits, the user is returned to their home directory. Is there a way to leave them in the /var/log directory?
I've tried the obvious things like:
trap 'cd /var/log' 0
with no success. I'm guessing that there's probably some really simple thing that I'm missing.
Thanks.
Signature · 7 lines
Bob Swift - To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.linux-learn.org/faqs
Quoted 7 lines · Bob Swift
This is going to sound like a really dumb question, but is there any way to have BASH leave the user in the current directory from the script, rather than returning them to the directory they were in when the script was called?
For example... the user is in their home directory and call the following BASH script:
Quoted 7 lines
#!/bin/bash cd /var/log lsWhen the script exits, the user is returned to their home directory. Is there a way to leave them in the
/var/logdirectory?
The script runs in a subshell. What you can do in this case is
source your-script' or just . your-script'
Ken
Signature · 6 lines
Live Long or Prosper! No, wait, that wasn't it... - To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.linux-learn.org/faqs
Quoted 1 line · Ken Moffat
The script runs in a subshell. What you can do in this case is
Okay, I understood the subshell part, and figured that's what was resetting everything.
Quoted 1 line
source your-script' or just. your-script'
That's what I was missing! I had completely forgotten about the "source" command. I also learned something because I didn't know about the "dot" trick.
Thanks.
Signature · 7 lines
Bob Swift - To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.linux-learn.org/faqs