LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash vs tcsh versioning ? (https://www.linuxquestions.org/questions/programming-9/bash-vs-tcsh-versioning-358019/)

puishor 08-29-2005 03:55 AM

bash vs tcsh versioning ?
 
HI !
I am desperate.
I got a little bash script.
On my PC it runs ok, I testet it in bash and tcsh shells.
The problem is that when I run it on other,remote shells;
Here are some first lines from it.

Code:

usage()
{
  echo -e "usage";
  echo -e "$0  proj_name  cr_number"
  echo -e "proj_name -- ex pcr6.1s"
  echo -e "cr_nuber  -- ex Q666111-02";
}

if [ $# -ne 2 ] ; then
  usage;
  exit; 
fi

if [ ! -e ~/tmp/ ] ; then
        mkdir ~/tmp/;
fi       

if [ ! -e ~/tmp/puishor ] ; then
        touch ~/tmp/puishor;
fi       

if [ ! -e ~/tmp/log ] ; then
        touch ~/tmp/log;       
fi       

date | awk 'END {print $1,$2,$3,$4}' > ~/tmp/puishor;
start_log=`cat ~/tmp/puishor`
start_log2=" $USER -- $start_log --  START ";
echo $start_log2 >> ~/tmp/log;

When I execute it on remote shell ( on far far far away linux Box ) without any argument it gives me




Quote:

-e usage
-e puishor.sh proj_name cr_number
-e proj_name -- ex pcr6.1s
-e cr_nuber -- ex Q666111-02
So in this case it runs ok.
But if I provide him 2 arguments, as it expected
and run

Code:

sh puishor.sh pcr6.1 Q01171801-07
it on remote shells ( in both, bash and tcsh ) says that
Code:

puishor.sh: test: argument expected
But in my shell that runs ok!!!!
Could someone help me please... at least clue me what is problem in ?

jlliagre 08-29-2005 04:26 AM

How do you run it as a remote shell ?

puishor 08-29-2005 04:37 AM

Quote:

How do you run it as a remote shell ?
I log through telnet ( I got an user ID and password ).
I copy on that machine my script ( through ftp GUI client, using the same user ID and password)
And there I execute it, using sh command.
Is that you asked me ?

jlliagre 08-29-2005 05:30 AM

Quote:

Is that you asked me ?
Yes.
Actually, you do not run your script remotely but locally on another host, but nevermind.

You should add a first line telling the O/S what interpreter to use to execute your script:
e.g.:

Code:

#!/bin/bash
...

Also add the "set -x" command to have each line traced while executed, that is usually enough to figure out the kind of error your are complaining of.

Code:

#/bin/bash
set -x
...

do not run you script with the sh command:
Code:

$ sh scriptName
Instead, make your script executable, and run it by calling it, possibly with a leading path if needed:
Code:

$ chmod +x scriptName
$ ./scriptName
...


puishor 08-29-2005 06:19 AM

That works.jlliagre,thank you very much.

I still got one question.
What is the difference between how do I run my script by "sh myscr"" or by "./myscr" ( with "chmod +x myscr" before that ) ?
Isn't the result the same ?

jlliagre 08-29-2005 07:24 AM

Quote:

Isn't the result the same ?
Yes, the result is the same, as long as "sh" execute the same shell and has the same name as the one defined in the interpreter line (#!/bin/bash).

vladmihaisima 08-29-2005 05:02 PM

There is also another way to execute a shell:
Code:

. ./myscr
This way the shell will be executed 'inside' the working shell (which means if you export an environment variable, after the execution of the script it will be preserved).

jlliagre 08-29-2005 09:29 PM

Beware that when using the source or "." command to run a shell script, an exit command in it will log you out ...


All times are GMT -5. The time now is 01:02 PM.