Unix Shell - Re: Running a script: How to reference the directory the script is located in.

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2006 > Re: Running a script: How to reference the directory the script is located in.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Running a script: How to reference the directory the script is located in.
Lew Pitcher

2006-10-24, 1:17 pm


jhagge@gmail.com wrote:
> I am writing a script using the Bourne shell. I know very little about
> Unix, but am familiar with DOS and writing batch files.


While that familiarity may help wrt understanding the general concepts
of shell scripts, it will intefere with your ability to design and
implement your shell script properly. MSDOS and MSWindows have a
completely different philosophy to Unix when it comes to the proper
placement of files, and the abilities and restrictions of users. Your
best bet is to learn how things are properly done in Unix rather than
trying to force Unix to fit how things are done in MSDOS.

> The script will be in a directory - I will call this directory DOGFOOD
> to make my explanation easier.... In DOGFOOD there will be some files
> I want to copy to a specific location on the users hard drive, this is


"a specific location" implies that you (or someone) already knows the
location. It shouldn't be hard to get a script to move files to a known
location.

> the only purpose of the script. The DOGFOOD directory could be
> located anywhere on the hard drive (it will be downloaded from the
> internet so I won't have control over where they save it). I am unsure
> how to reference the DOGFOOD directory in the script so I can copy the
> files in DOGFOOD to where they need to go.


Ahhh.. so your intention is to have the user download several
components, including a script, and then have the script grab those
components and install them. I've seen better designs, but I've seen
worse.

> My best guess is to create
> a randomly named file in DOGFOOD, then do a find for the file and
> somehow grab the path from the output of find... surely there is a
> better way to do this.


Much better ways. But then again, your goal is unrealistic, and the
"better ways" would require a design change to your process.

> My other question is similar. This script is running on an OS X
> machine. How do I reference the "system drive" ?


There isn't any such thing. As I said, lose your MSWindows/MSDOS
preferences and learn how Unix does things.

[snip]

Here are a couple of alternatives you can think about :
1) package script and files into a shar file. Have users download shar
file and run it. shar file will unpack files into their proper place
without having to first locate the files. This works because the files
are /part/ of the shar file to begin with.

2) Script manages download itself. User downloads and runs script,
script downloads files to proper directories.

HTH
--
lew Pitcher

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com