|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
Quote:
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? |
|
#5
|
|||
|
|||
|
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* |
|
#6
|
|||
|
|||
|
Is there any rights needed to run shell scripts. I am working on an university machine.
|
|
#7
|
|||
|
|||
|
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 |
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
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 |
|
#10
|
|||
|
|||
|
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 ![]() |
|
#11
|
|||
|
|||
|
Thanks a lot
Sathi ![]() |
|
#12
|
|||
|
|||
|
Quote:
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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Problem with Scripts |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|