Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can I change the users directory 2

Status
Not open for further replies.

Birbone

MIS
Dec 20, 2000
141
0
0
US
I'm writting a script to move some files into a specific directory and would like to dump the user into that directory to review the files them just imported. Can I do that from within a script. I know I can read their imput, how do I push the command?

Here's what the cmd line would look like:

user@hosts:/dirA/subdir> getlogs.sh
user@hosts:/dirD/logsdir>

-B :cool:
 
You can't really... one option would be to launch a sub shell in that directory, but the user would need to know that they have to 'exit' from that sub shell before your script completes.

Either that or the user could source your script instead of running it, e.g. . scriptname (or source scriptname if your shell supports that), which would make the directory change persistent in that shell.

Annihilannic.
 
Some programs (Midnight Commander comes to mind) do this by having the main program, when gien an option, output a string containing the destination directory, then creating an alias or shell function that executes the command and [tt]cd[/tt]s to its output.

Programs like Midnight Commander that take this approach normally do so because the program itself allows the user to change directory while using the program, and the user may expect to stay in a directory once they leave the program.

Having a program do this for the sake of "convenience" may be a bad idea, as it may not really be convenient. If the user expects to stay in the old directory, the forced change might be annoying or even destructive.

I'd suggest not having the script dump users anywhere. If you really need this functionality, I'd suggest making it an optional feature that users can choose to turn on if they find it convenient.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top