scripting pushd popd
i have a script in my bin directory - so i could use it from any location
I want it to display certain group of files in a directory. I want to use pushd to put this directory on top of the stack, in case I want to grep something out of the files without using the whole path from the directory that i am in. I don't want to use cd because i want to use popd to go back to the previous working directoy. However when i use the pushd in the script, it leaves me in the current working directory. the pushd command does nt put me into the directory that i want. after the script executes, i ma left in the directory that i am working from Code:
#!/bin/bash |
Your shell process before you run the script remains unchanged because the activity in the script is in a different shell process. It sounds as if you want to "source" the file in the current process which can be done with the dot symbol.
Code:
. ~/bin/tspin |
I source the file at the beginning of the script and when I run it i get a segmentation fault.
Code:
i don't understand what sourcing is. when i do a locate on the pushd to source it i get his file path. when I sounrce this path i get an error. casper@casper3 bin $ locate pushd /usr/share/man/man1/pushd.1.gz why did you source the directory that the script is in? |
Code:
casper03 bin $ more /tmp/foo |
Code:
###### This file is ~/bin/tspin --- whatever you do never put any text in here causing it ti call itself. Code:
casper03 bin $ |
ok that work - kinds defeats the usability - like why put it int he bin directory when i have to source it each time i use.
maybe I could alias it - or make another script that sources the files. thank you very much |
The way I usually change directories in shell scripts is with
Code:
olddir=`pwd` Also remember that cd "remembers" the last directory it was in and you can use 'cd -' to jump back. |
cd -
that is a really good idea. that is actually what i was looking for - a way to pop in to a directory, make changes, and then pop back to where i was. thank you very much. |
All times are GMT -5. The time now is 02:50 PM. |