SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old February 3rd, 2004, 10:30 AM
sathi sathi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 27 sathi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem with Scripts

a=Jim
b=Plank
echo $a $b
c="Jim Plank"
echo $c
d="$a $b"
echo $d


For the above script, echo $d just shows ' Plank' but when each command is typed in console it works fine and shows 'Jim Plank'

Can you please help me out??

Thanks,
Sathi

Reply With Quote
  #2  
Old February 3rd, 2004, 11:20 AM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
Did you use the 'hash bang' header in your script?? Because here it works fine (I copy/paste the code, just inserted the #!/bin/sh at the top):
Code:
#!/bin/sh

a=Jim
b=Plank
echo $a $b

c="Jim Plank"
echo $c

d="$a $b"
echo $d


$ ./tester
Jim Plank
Jim Plank
Jim Plank

Reply With Quote
  #3  
Old February 3rd, 2004, 12:04 PM
sathi sathi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 27 sathi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
After adding that header it says

: bad interpreter: No such file or directory

But there is a file "sh" in /bin and it executes in command line as a shell

Reply With Quote
  #4  
Old February 3rd, 2004, 12:18 PM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
Quote:
: bad interpreter: No such file or directory


The shell tells you it does not understand the first line.

If /bin/sh excists (if it is a link, it should point to /bin/bash) and can be executed from the shell then there must be a typo somewhere in the first line (the hash-bang line).

#!/bin/sh
A hash (#) followed by an exclamation mark (!) followed by full (absolute) path to sh (/bin/sh).

There should be no spaces in this line.

What happens if you copy/paste my example and try to execute it?

What unix flavor are you using?

Reply With Quote
  #5  
Old February 3rd, 2004, 02:14 PM
sathi sathi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 27 sathi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a lot for your help!!
I copied ur script and it shows the same error.

I am using Linux version 2.4.20-28.9

I have listed down the directory entries for sh and bash files under /bin

lrwxrwxrwx 1 root root 4 Nov 27 16:05 sh -> bash*
-rwxr-xr-x 1 root root 626028 Apr 9 2003 bash*

Reply With Quote
  #6  
Old February 3rd, 2004, 02:24 PM
sathi sathi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 27 sathi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Is there any rights needed to run shell scripts. I am working on an university machine.

Reply With Quote
  #7  
Old February 3rd, 2004, 02:44 PM
sathi sathi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 27 sathi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I downloaded te script file
http://users.sdsc.edu/~steube/Bshell/Scripts/simple.sh
and run it...
It ran well.
I just opened the file and added my code.
It worked perfectly.
I donno how this works. But my problem is solved for now.
Thanks,
Sathi

Reply With Quote
  #8  
Old February 3rd, 2004, 03:50 PM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
You need execute rights for the script you try to run.
If you are not the owner and do not belong to the group, the 'world' needs execute rights.

Compare the script you downloaded with the one you try to run and fails.

Reply With Quote
  #9  
Old February 8th, 2004, 04:48 AM
sathi sathi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 27 sathi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The only difference I can find is that, the one which I downloaded seems to be in UNIX file format, while the one created was in windows.
Sathi

Reply With Quote
  #10  
Old February 8th, 2004, 06:48 AM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
That' s a huge difference and explains why it isn't working.

If you have (g)vim on you linux box it's easy to change it from win format to linux format: Load the file in vim and type the following in command mode:

: set ff=unix

Save the file and it should be a unix file (check with $ file <name-file>).

From now on use a linux/unix when creating scripts for these platforms

Reply With Quote
  #11  
Old February 8th, 2004, 06:56 AM
sathi sathi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 27 sathi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

Thanks a lot
Sathi

Reply With Quote
  #12  
Old February 7th, 2005, 12:36 AM
prjames prjames is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Wales
Posts: 25 prjames User rank is Corporal (100 - 500 Reputation Level)prjames User rank is Corporal (100 - 500 Reputation Level)prjames User rank is Corporal (100 - 500 Reputation Level)prjames User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 21 m 8 sec
Reputation Power: 0
Red face

Quote:
Originally Posted by druuna
That' s a huge difference and explains why it isn't working.

From now on use a linux/unix when creating scripts for these platforms


Bingo. Helped me as well.
Similar problem, but for some reason had Kate editor set to Windows/dos end of lines - why? I couldn't say.

Cheers.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Problem with Scripts


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway