[Basic Query]bsh script in tcsh shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Basic Query]bsh script in tcsh shell
# 1  
Old 07-20-2011
[Basic Query]bsh script in tcsh shell

I am a beginner (Just 2 days oldSmilie ), i will really appreciate if you can solve my silly queries as below:

Lets say i write a script like this

Code:
#!/bin/bsh
clear
#to read name from keyboard
echo "your name please.."
read fname
echo "you just entered $fname"
exit 0

My environment is set to work in tcsh.
My query are:
a) how does placing !/bin/bsh as comment results in its execution as bsh shell? AS i am a beginner, i need to know if it is an exception ? how does placing a path as comment affects the execution of code.

b)If, say i place the path as second line of my comment. assume my first two lines are as below

#just comment
#!/bin/bsh

The code executed, but i also get some errors which says command not found.

c) Is it compulsorily to place "exit 0" at the end of every script? where should it be used?
# 2  
Old 07-20-2011
The "shebang" line is not an ordinary comment (btw do you mean #! /bin/bash)
It instructs the shell that executes the script which interpreter to call on the script when it is the first line of the script.

The value you exit from a script sets $? in the parent shell, this can be used to "report" an error in the running of the script to the parent or to make decisions based on the exit status.

A facile example which checks for the existence of the user in /etc/passwd before running the useradd program.
Code:
seterr.sh
8<------->8
#!/bin/bash
exit 1

verified_useradd.sh
8<--------------------------->8
#!/bin/bash
found_user=$(grep -e  "^$1:" /etc/passwd)
if [ "X$found_user" == "X" ] ; then
    # no such user in /etc/passwd yet
    /usr/sbin/useradd $i
    exit 0
else
    echo "User $i exists, please retry with a new user name"
    exit 1
fi


new_user
8<-------->8
seterr.sh
while [ $? -ne 0 ] ;do 
   echo "Please priovide a username"; 
   read uname; 
   verified_useradd.sh uname;  
done

In the example above the while loop will continue until verified_useradd.sh returns with no error, thus guaranteeing a user has been added (or at least that useradd was called
# 3  
Old 07-20-2011
Hey,
I meant #!/bin/bsh only, and its working.

Thanks for introducing the concept of shebang, I wasn't aware of it.

Last edited by animesharma; 07-20-2011 at 06:28 AM.. Reason: solved
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help! Basic shell script advice

##### (2 Replies)
Discussion started by: AidoPotato
2 Replies

2. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

3. Shell Programming and Scripting

tcsh env setting using shell script

Hi All, I have made a file file usercreate.sh & it has to run in tcsh env & needs some path to be set. my script is as below. ########################## #!/bin/csh setenv PATH "/usr/lib/java/class" setenv LD_LIBRARAY_PATH ########################### but when i am ruuning my script... (1 Reply)
Discussion started by: ajaincv
1 Replies

4. Shell Programming and Scripting

Basic shell script help

Im trying to make a script that simply adds a word to the last available line in a txt file without overwriting any previous lines. Ive googled this and there are great examples but no one explain what each function does, and i dont entirely understand how it works. Basically Im looking for... (7 Replies)
Discussion started by: kylecn
7 Replies

5. Shell Programming and Scripting

Basic Shell Script Help

Lets say I wanted to create a script that would show what people are doing on my machine using the w command and refresh in about 6 seconds. What would be the easiest way to do this? I pretty much want the script to loop until I stop it. I'm using the BASH shell by the way. Help is appreciated.... (1 Reply)
Discussion started by: c4391
1 Replies

6. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

7. Shell Programming and Scripting

shell script basic doubt

hi, I am new script learner, so my basic doubt is , how to store value of any command in a variable example $ ls | wc -l i want to stote the output of this in a variable c. so that i can use c in if else loop. and when do we use " ` " symbol in script.. can anyone also tell for... (5 Replies)
Discussion started by: hi2_t
5 Replies

8. SCO

Bsh shell on SCO

I everybody! I am trying to install the bsh shell on a SCO unix and i don't know how. The deal is that i have an old SCO unix running with an old system made with cobol, so it works with shell menus and it use a variety of a shell called bsh (Business Shell) so i search for a package to install... (5 Replies)
Discussion started by: martocapo
5 Replies

9. Shell Programming and Scripting

Basic Shell script syntax help

Hi All, I am new to shell scripting. I have a variable which holds a numeric value.I have to check whether this variable holds a value between(0- 8),(8-17)(17-24).How do i write this syntax using if in shell scripting. Thanks Vignesh (2 Replies)
Discussion started by: vignesh53
2 Replies

10. Shell Programming and Scripting

A basic query

In a Bourne shell script, I often come across statements involving `sh -c`. I was not able to make out if any reason is there behind that. example: echo `sh -c 'date'` killing all server processes Instead of the above, I can use echo `date` killing all server processes. Is there any... (1 Reply)
Discussion started by: asutoshch
1 Replies
Login or Register to Ask a Question