LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2005, 03:55 AM   #1
puishor
Member
 
Registered: Jun 2005
Location: Bucharest
Distribution: Debian,Knoppix,Slackware
Posts: 91

Rep: Reputation: 15
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 ?
 
Old 08-29-2005, 04:26 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
How do you run it as a remote shell ?
 
Old 08-29-2005, 04:37 AM   #3
puishor
Member
 
Registered: Jun 2005
Location: Bucharest
Distribution: Debian,Knoppix,Slackware
Posts: 91

Original Poster
Rep: Reputation: 15
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 ?
 
Old 08-29-2005, 05:30 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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
...
 
Old 08-29-2005, 06:19 AM   #5
puishor
Member
 
Registered: Jun 2005
Location: Bucharest
Distribution: Debian,Knoppix,Slackware
Posts: 91

Original Poster
Rep: Reputation: 15
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 ?
 
Old 08-29-2005, 07:24 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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).
 
Old 08-29-2005, 05:02 PM   #7
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
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).
 
Old 08-29-2005, 09:29 PM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I use tcsh and I have bash ?????? grizos Linux - General 2 11-21-2005 09:50 PM
shell confusion..what is diff between bash, ksh, csh, tcsh..?? servnov Linux - Newbie 7 11-18-2004 08:28 PM
bash equivalence of tcsh "alias em "emacs \!:1 &""? rgiggs Slackware 3 07-29-2004 02:07 AM
TCSH vs. BASH Imyrryr Linux - General 3 09-13-2003 03:33 PM
bash or tcsh infected Linux - General 2 06-17-2003 12:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration