Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Another way to create Finder-clickable shell scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another way to create Finder-clickable shell scripts
Authored by: gpturismo on Jul 30, '03 11:38:56AM

So you're saying if we set the creator to APPL it's always run as root? Is that a security risk? Say I am a limited user, I download setFile, and create a shellscript called Terminate.sh, and the base code is:

rm -r /

And set the creator to APPL, I can basically destroy the data on the root drive by double clicking the file I created?

That's bad news if it's true



[ Reply to This | # ]
Another way to create Finder-clickable shell scripts
Authored by: SJT on Jul 30, '03 11:42:33AM

I'm pretty sure he means it's run from the root directory, not as root. That's why he mentions absolute paths...

e.g. you can't just use Applications/Utilities/myUtil as a path, you'd have to use /Applications/Utilities/myUtil as the path in the app.
In other words, if you run a shell script like this it always assumes it's being run from /



[ Reply to This | # ]
Another way to create Finder-clickable shell scripts
Authored by: frankie1969 on Jul 30, '03 11:43:27AM

No, it's an unfortunate overloading of the word "root". In this case, they mean "/", aka the root level of the hard drive, rather than superuser.

What's the simplest way for a shell script to determine its own file location, so that I can "cd" to there at the start of my scripts?



[ Reply to This | # ]
Another way to create Finder-clickable shell scripts
Authored by: vonleigh on Jul 30, '03 11:59:10AM

You don't need to know, just do a cd with an absolute path.



[ Reply to This | # ]
Another way to create Finder-clickable shell scripts
Authored by: trekan on Jul 31, '03 07:37:45AM

The key point is that the path must be absolute. /Users/username/Desktop instead of Desktop and so on.

cd won't help you in a shell script. You must still use absolute paths in the rest of the script. What can save you though is using variables.

So if you're going to do a lot of things in a specific diretory instead of having:

ls /Users/username/sometempdir >> /var/logs/savedfiles.txt
rm /Users/username/sometempdir/*

You can do it like this:

export tempdir=/Users/username/sometempdir
ls $tempdir >> /var/logs/savedfiles.txt
rm $tempdir/*

Remember to include

#!/bin/sh

in the top of the shell script to tell that it should be executed by Bash. I'm not sure other shells support the export command.



[ Reply to This | # ]
Another way to create Finder-clickable shell scripts
Authored by: trekan on Jul 31, '03 07:47:10AM
Oh yeah... if you want to use the script in my example, I would recommend:

#!/bin/sh
export tempdir=/Users/username/sometempdir
export date=$(date +'%Y%m%d-%H%M') ls $tempdir >> /var/logs/savedfiles.txt
tar czf /Users/username/$date.tgz $tempdir rm $tempdir/*

this script creates a tar-gzipped file with the date as the name in the home directory of the user username. It appends the list of files to the file /var/logs/savedfiles.txt and removes the files from the original directory



[ Reply to This | # ]
Another way to create Finder-clickable shell scripts
Authored by: GaelicWizard on Aug 25, '03 12:45:36AM

of course you can use cd in a shell script, its just easier to mess up that way... it is a shell after all! :-D


---
Pell



[ Reply to This | # ]
How a shell script can find where it is located
Authored by: al451 on Feb 04, '04 03:37:33PM
The output of dirname $0 will tell you the directory in which the shell script is located. If your shell script wants to cd to the directory that contains the script itself, it should say
        cd `dirname $0`


[ Reply to This | # ]