Build script for all shells


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Build script for all shells
# 1  
Old 04-13-2005
Build script for all shells

Hi,

I made a build script for the product I am working on.

The script was made in the /bin/sh shell.

My first line in the script (after the #! /bin/sh and following # lines ) were,
Code:
if [ $SHELL != /bin/sh ] ; then
  /bin/sh
fi;

It works well with my sh shell. I run the script as

sh build.sh

Now I ran this script on another machine with $SHELL as /bin/csh

It failed to build. I then tried

./build.sh and it works well.

Why the change in behaviour and whats the difference between sh and ./

Can a script be written in such a manner that it would run in any shell ?

Thanks,
Vino
# 2  
Old 04-13-2005
See this link for an explanation of ./. As for building a script that will run in all shells, I suppose it is possible to do this but I would imagine that it would be difficult to get it right. Some shells, such as csh, are not as full featured as say ksh. The script you are building would have to be built with the lowest common denominator of shell functionality common to all shells.
# 3  
Old 04-13-2005
Here is an article that discusses this topic
# 4  
Old 04-13-2005
instead of checking for $SHELL ... just set the first line of the script to "#! /bin/sh" and run it with either ./script_name or /path/to/script_name ...

checking for $SHELL is unnecessary ... you might check for the correct shell path if you are porting the script to different OS platforms (i.e., /bin/ksh for Solaris and /usr/bin/ksh for HP, etc.) but that doesn't sound like that's what you're trying to do here ...
# 5  
Old 04-13-2005
Um, it doesn't work in csh because "if [ $SHELL != /bin/sh ]; then" is not valid csh syntax.
# 6  
Old 04-13-2005
Quote:
Originally Posted by criglerj
Um, it doesn't work in csh because "if [ $SHELL != /bin/sh ]; then" is not valid csh syntax.
it doesn't matter what shell you are using for your current environment, the script will use the shell you set it to use through the "#!" directive ...
# 7  
Old 04-13-2005
The OP is attempting to write a shell that runs under all shells (not specific to bourne) and by not specifying a magic number in the script.

Again, the script you are building would have to be built with the lowest common denominator of shell functionality common to all shells. As criglerj pointed out, you must exclusively use syntax that is common to all shells to get this project to work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX shells script to echo out the date value

I appreciate if someone answer this question for my learning purpose: Given a filename structure of a COUNTRY CODE, file type, date (YYYYMMDD) and two digit attempt number with an extension of ".dat", write a UNIX shells script to echo out the date value. Example: ... (1 Reply)
Discussion started by: shumail
1 Replies

2. Shell Programming and Scripting

Build.xml invocation by Build Script

Hi I have a build.xml file and I can run it on Windows via cmd. Now I want to write a script to invoke the same. Is there a way to do this? (1 Reply)
Discussion started by: ankur328
1 Replies

3. UNIX for Dummies Questions & Answers

Too Many Arguments Error - shells script

Hi, I am getting the below error : error at the if condition start and when I print the value of TEST, it displays two values as below /home/xyz/out/file1.txt /home/xyz/out/file2.txt if ; then mv $TEST $TARGETDIR/ fi Tried by enclosing it in double quotes "$TEST",... (4 Replies)
Discussion started by: sudhagk
4 Replies

4. Shell Programming and Scripting

Run commands in a script in different shells

Hi to all, i have the following problem... i want to run three commands in a script in different shells... the first command is running always and is needed for the second on to run properly... example # Procedure 1 xterm -e exec1 arg1 arg2 # Procedure 2 xterm -e exec2 arg1 arg2 #... (6 Replies)
Discussion started by: paladinaeon
6 Replies

5. Shell Programming and Scripting

Calling a function which uses expect from a shells script

Hi all, This is the first time i am using expect. I am trying to call a function with in the shell script. The function will shh to a new server and will pass the password using expect and send. I need help in calling the fuction i am getting follaowing errors... here the script ... (8 Replies)
Discussion started by: firestar
8 Replies

6. Shell Programming and Scripting

Oracle environmental variables in shells script

Hi, Getting below error on executing the shell script which initiates sqlplus How to set oracle enviornment variables in the shell script ? With Regards (3 Replies)
Discussion started by: milink
3 Replies

7. Shell Programming and Scripting

Question regarding shells and subshells when a script is run

I have the following script running with nohup on one of my servers: #!/bin/bash #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #set log number #i=1 #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #Check if log exits, if so incrememnt log number up so we don't clobber #while... (8 Replies)
Discussion started by: DeCoTwc
8 Replies

8. Shell Programming and Scripting

Rename a lot of files using shells script

Hi This is the list file that i have : The files is more than this. I will rename one by one file become like this : So just change the time stamp 200906 become 200905. Is it possible using script ? Thanks (3 Replies)
Discussion started by: justbow
3 Replies

9. Shell Programming and Scripting

Using different shells in one script

Hi, Is it possible to use multiple shells in one script. There are sometimes we need to club shell specific commands in single script. for example in bash mode we use -e with echo to use Escape sequence but in ksh it is not required. How to tell a UNIX command to run in a specific shell. ... (2 Replies)
Discussion started by: sanjay1979
2 Replies

10. Shell Programming and Scripting

Validating variables in shells script

All Can you help me to validate a variable only for string and digit. That is variable should either fully alphabets or digits. Please send me result to my mail id also: REMOVED Thanx in advance Regards Deepak Xavier (1 Reply)
Discussion started by: DeepakXavier
1 Replies
Login or Register to Ask a Question