scripts for dummies


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers scripts for dummies
# 1  
Old 06-30-2001
scripts for dummies

í have no idea how to write a script. can someone help? how would i write a script that will do the following commands

mkdir temp
cp * temp
cd temp
ls

i want to be able to do a set of commands by typing in only one command. i´m a windows user that is trying to learn unix, finally :P so i´m familiar with the dos way where we simply just create a file that ends with a .bat so a temp.bat is the script where we simply type in temp to run it. i´m not sure how unix works so please explain as if telling a newbie...heehee. and do i have to somehow make the script file executable, if so then how?

thanks,

and if its you answering my questions again, andy...thanks alot! i can´t do the bash stuff u told me before cuz i just changed my shell to bash and it says it will take about 3hrs to change it. once its done then i will test out what u said. thx man...
# 2  
Old 06-30-2001
Sorry that you've got to wait 3 hours, I assumed that you were running your own Unix box.

Try copying the following to a file called myscript

#--------
#!/bin/sh
mkdir temp
cp * temp
cd temp
ls
#----------


Next you should make the script executable: "chmod o+x myscript", if you don't make the file executable then you'll need to type "sh myscript" to execute the script.

If you don't want to add the file to your path then you'll need to type ./myscript from the scripts directory.
The path can be find by typing "echo $PATH"

Andy Hibbins
# 3  
Old 06-30-2001
i got it to work when doing sh myscript
but i can´t get it to work by just typing myscript
i changed it to executable by chmod o+x myscript, but when i type myscript after that then it says permission denied. i don´t know why when this is my login name and all i´m using.

then i tried to put it in the path but when i did echo $PATH i get

/usr/local/bin:/usr/ccs/bin:/opt/SUNWspro/bin:/usr/ucb:/usr/bin:/bin:/usr/games:
/usr/bin/X11:/usr/openwin/bin:.

i´m not sure where the script dir is. help?

# 4  
Old 06-30-2001
Can you try type "ls -l myscript" and then tell us what the file permissions are.

If the file is executable then you could type "./myscript" to execute it aslong as your in the same dir.

You could make your own script dir say scripts: "md ~/scripts"

Then add the scripts dir to your path PATH=$PATH:~/scripts

~ is just a shortcut for your home dir.


Andy Hibbins
# 5  
Old 06-30-2001
this is my permission

-rw-r--r-x 1 davidlee 71 Jun 30 11:09 myscript

doesn´t the x mean its executable, and i am logged in under davidlee, thats me Smilie

i even created the dir of scripts and moved the file under it and added the scripts dir under my path. i typed in myscript and it still says permission denied. ideas?
# 6  
Old 07-01-2001
Hi

The file permissions that ls -l shows up does not have executable permissions for the user i.e you i.e davidlee. So you need to set the executable permissions for the script file (myscript). to do this give chmod u+x myscript
the ls -l myscript will then show
-rwx-r--r-x
i.e you now have the executable rights and now you can run myscript by typing just the filename.
Hope this works.


# 7  
Old 07-02-2001
Well, This is not the exact answer to your question.
But may help you....

Remember 3 numbers.
Read 4
Write 2
Execute 1

in chmod command you can give the access rights to 3 kind of users.
owner , users in the same group and otheres

if you say
chmod 765 filename
it means
owner of the file gets 7 (4+2+1 , ie, read, write, execute)
group people get 6 (4+2 , ie read and write)
others get 5 (4+1 ie. read and execute but not write)

to give any access permission add up the number for that access permission.

Pls correct me if I am wrong.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

C++ for dummies: how to compile a code.

Hi. I wrote a small programm which shows me display's refresh rate #include "stdafx.h" #include "windows.h" #include "iostream" using namespace std; int _tmain(int cout) { HDC hDCScreen = GetDC(NULL); int RefreshFrequency = GetDeviceCaps(hDCScreen, VREFRESH); ReleaseDC(NULL, hDCScreen);... (1 Reply)
Discussion started by: urello
1 Replies

2. UNIX for Dummies Questions & Answers

I know this is probably top of the Dummies questions!

Hello: I am a very new Newbie. This is not a homework question. The assignment question was actually on the use of the 2 different inputs 'read' and 'cat' ... that I know and turned in an hour ago. I don't need help with that. My question, like I said, probably sounds really dumb to most of... (4 Replies)
Discussion started by: ZaraJC
4 Replies

3. UNIX for Dummies Questions & Answers

dummies question

Please help to answer some highlighted question below. 1. How to create more than 1 partition in a single hard disk? 2. How to format the created partition to be viewable like in windows C: or D: ? 3. How to use pen drive in unix environment? 4. How to find a file starting with... (8 Replies)
Discussion started by: jimmyysk
8 Replies

4. UNIX for Dummies Questions & Answers

I am real Dummies , I am Questions

I want to know data about 1. Overview 2. Process Management 3. Memory Management 4. File System Management 5. Secondary Storage Management 6. Protection and Security Systems of UNIX OS Thank Alot. (1 Reply)
Discussion started by: coolmara04
1 Replies

5. Solaris

Solaris for dummies

Is there one command that will display all system information on a Solaris host running Solaris 8? System information such as model, memory, CPU, disk space etc. etc. (2 Replies)
Discussion started by: mita
2 Replies

6. News, Links, Events and Announcements

UNIX for Dummies Test

A goofy UNIX test: http://www.majon.com/cgi-bin/IQ?Q=unix WARNING: ANSWERS ARE BELOW!!!! IF YOU WANT TO DO THE TEST BEFORE SEEING THE ANSWERS, DON"T READ FURTHER ;) (13 Replies)
Discussion started by: Neo
13 Replies

7. Shell Programming and Scripting

Perl for Dummies

Hi all. iam new to this and i want to learn perl Any good website out there ?? anything will do thanks :( (1 Reply)
Discussion started by: perleo
1 Replies

8. Post Here to Contact Site Administrators and Moderators

Unix for Dummies FAQ

I have created a small FAQ for the "Unix for Dummies" forum. Hopefully this will be useful, as there are questions which are asked (and answered) repeatedly. <A HREF="http://www.droflet.net/unix_dot_com_faq.html">http://www.droflet.net/unix_dot_com_faq.html (0 Replies)
Discussion started by: PxT
0 Replies
Login or Register to Ask a Question