aspose file tools*
The moose likes Linux / UNIX and the fly likes problem with execution of script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "problem with execution of script" Watch "problem with execution of script" New topic
Author

problem with execution of script

Balaji Prasad
Greenhorn

Joined: Feb 01, 2010
Posts: 3
I wrote a sed command in unix(solaris)to append a word to say second line of the script..
contents of the script called test.sh has just 2 lines.




When I execute it in command line, it appends the line after 3rd line.

But when I execute the script like this-> "test.sh" , nothing happens.

But when is run the script as "ksh test.sh", the desired result is produced.

How does it make a difference?
I did a echo $SHELL to find that my current shell is /bin/ksh
"whence ksh" gives me /bin/usr/ksh

running the script by mentioning the shell explicitly gives me right results(/bin/ksh test.sh or /bin/usr/ksh test.sh both gives right results )
but just test.sh doesn't work. I assume it must use the default shell-/bin/ksh

What is happening here?
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

To be run without an explicit 'ksh' the script needs to have the 'executable' bit set and the OS needs to know which program to use to interpret your script. If prefixed by #! (hash bang), the OS will treat the first line of your script as defining the name of the program to run to interpret the rest of the script. See http://en.wikipedia.org/wiki/Shebang_%28Unix%29 .

If you are expecting it to use ksh then I would expect the script file to contain


To set the executable bit



Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with execution of script