This is going to sound dumb but...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers This is going to sound dumb but...
# 1  
Old 11-02-2005
Question This is going to sound dumb but...

how do i create scripts while in unix? Could someone tell me in the format of:
commands
script
commands
or something like that or even however you feel comfortable but could you try to explain it thoroughly. just want something where i can look at it and be able to put anything i want in there. I am just going to stop typing before i confuse anyone but if anyone knows what im talking about and can help please do?
# 2  
Old 11-02-2005
Shell programming in sh.

1) Every shell file gegins with #!/[path to shell]/[name of shell]! to use bash, for example you would begin your shell script with

Code:
#!/bin/sh

to use tcsh you could use

Code:
#!/bin/tcsh

2) When you declare variables just type the variable name followed by the = sign. For example to create a variable named NAME and set it to "ME" enter

Code:
NAME="ME"

3) When using a variable in an expression (like an if, and so forth) precede the variable name by $. For example, to ser a variable caled VAR2 to NAME enter:

Code:
VAR2=$NAME

4) You can use commands in shell scripts as you do the shell. The advantage of shell scripts is that you can use macros. For example to list all files and all directories in the current directory that begin with NAME enter

ls $NAME*

The following file gets all of the files returned by ls and stroes them in foo. after that, it takes the last file listed by ls and stores it in final value. Then it prints the value of finalvalue.

Code:
finalvalue=""

for foo in `ls`
do
  echo $foo
done

finalvalue=$foo

echo "$finalvalue"


I would list more, but I ran out of time. Hope this helps.
# 3  
Old 11-03-2005
# 4  
Old 11-03-2005
You would have found this in the FAQs if you had checked: Unix Tutorials/Programming Tutorials/Shell Scripting Tutorials. On this page, check the Shell Scripting Tutorials section.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

i have few dumb questions..

i wanna learn UNIX so 1. how should i start? 2. which book should i use? 3. which environment is best for learning n then getting job? thanx in advance........:) (1 Reply)
Discussion started by: vjai
1 Replies

2. UNIX for Dummies Questions & Answers

i have few dumb questions..

i wanna learn UNIX so 1. how should i start? 2. which book should i use? 3. which environment is best for learning n then getting job? thanx in advance........:) (1 Reply)
Discussion started by: vjai
1 Replies

3. UNIX for Dummies Questions & Answers

this is a very dumb question...i know... :(

hi, when we do an "ls -l" on a directory, we get the listing of the contents of that dir... what is the meaning of some numbers...example in ; -rw-r--r-- 1 idr supp 0 Feb 18 19:41 dmesg drwxrwsrwx 2 root sys 96 Dec 27 15:31 test09 drwxr-xr-x 3 bin ... (1 Reply)
Discussion started by: cromohawk
1 Replies

4. UNIX for Dummies Questions & Answers

Another dumb question but...

When getting a listing of files using "ls -l", my output shows the permissions, #oflinks???, owner, group, size, month-day-time, and file. In the example below, how would I know what year the file was last modified? -rw-rw-r--, 28, root, root, 2048, Oct 28 15:10, somefile.txt (2 Replies)
Discussion started by: KGee
2 Replies

5. UNIX for Dummies Questions & Answers

Another dumb question...

Probably a really easy one for you guru's out there...:rolleyes: I need to make sure the reverse address lookup daemon in rarpd, is running. How do I do so? :confused: Did a grep for the process but couldnt find it, also looked in all the normal places, /bin etc... Cheers (1 Reply)
Discussion started by: JayC89
1 Replies

6. UNIX for Dummies Questions & Answers

Ok really dumb question but...

Does anyone have detailed info on how to download the files. I go to www.freebsd.com and then i dont know what to do. I dont know why i dont know but im drawing a complete blank so is there anyone that can provide a step by step procedure for downloading/installing Linux? :confused: :confused: (3 Replies)
Discussion started by: Corrail
3 Replies

7. UNIX for Dummies Questions & Answers

Two dumb questions

It's obvious I'm a newbie after today, so I come to ask two questions. Or, solutions to two problems, anyway. I'm running KDE 3.1 on SuSE Linux 8.2, for reference. 1. After downloading programs for KDE and running 'configure', I infallably get an error that states: 'in the prefix, you've... (1 Reply)
Discussion started by: Darkstripes
1 Replies

8. UNIX for Dummies Questions & Answers

really dumb question...

ok i decided to go with Mandrake so i went to the site to download it and that took me to a mirror site. ok. so once i get there were can i find the install file(s) that i need? i only see a series of folder and files. the ones that say intall are instructions but i don't see the files themselves.... (3 Replies)
Discussion started by: justchillin
3 Replies

9. UNIX for Dummies Questions & Answers

Dumb thing to do

I'm writing for a friend. He has a SPARC system at home that has Solaris 7 on it. He did not yet create a user on it and has not set the CONSOLE to allow the root user to log in remotely. Now, something happened and the system will not even boot to the Boot PROM. How can he get into the system... (4 Replies)
Discussion started by: danh
4 Replies

10. UNIX for Dummies Questions & Answers

dumb question

My problem is as follows: I have to write a korn shell script which will run mutiple java applications one after one. For example, I will execute the java application A first, after it is done I will run application B. My question is how do I do this? How does my korn shell script know that... (1 Reply)
Discussion started by: madhab99
1 Replies
Login or Register to Ask a Question