This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

making an executable shell script

 
prateek urmaliya
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to run my jar from Unix box ,
I have created an executable jar abc.jar
and using this script

then named it myscript.ksh

but when I try to run myscript.ksh
I am getting ksh: myscript.ksh: not found
I did a ls -l and all have execute permission.
Am I missing something ?
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is . (CWD) in your PATH?

Try

echo $PATH
./your_script
 
prateek urmaliya
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it's not and I can't append it to PATH
also I don't have permission to copy the script in the DIR's that are in PATH.
but I plan to execute this script from CWD ,Is there a way around this ?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You never can append a script to the path - just directories.

And with

you start your script from the current directory.
 
prateek urmaliya
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is . (CWD) in your PATH?

No it's not and I can't append it to PATH

I tried doing a

but no luck ,I have execute permission on this file

but when I do a
It's running fine,
what can be causing this ?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be clear on this, you typed

./myscript.ksh

and it didn't run? What actually happened?
 
prateek urmaliya
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,
I did a from my CWD that holds myscript.ksh
and got a
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go back and look at what Ulf asked you to try.

The ./ at the beginning is important.
It says run the myscript.ksh in this directory.

Unlike with Windows, Unix by default, doesn't automatically look in the current working directory for programs.
 
prateek urmaliya
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

I tried what Ulf suggested but still I am getting

What could cause this ?
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by prateek urmaliya:
Hi Ben,

I tried what Ulf suggested but still I am getting

What could cause this ?


  • Open a new terminal.
  • Change directory to where your script is.
  • [list]Do a [/list]
  • Execute your script like you have been advised multiple times.
  • Now take a snapshot of your terminal, upload it, and send us a link to this snapshot.

  • - Anand

    [Edit: Added closing List terminator]
    [ April 25, 2007: Message edited by: Anand Hariharan ]
     
    prateek urmaliya
    Ranch Hand
    Posts: 87
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Anand,

    I have sent you a PM.
     
    Anand Hariharan
    Rancher
    Posts: 272
    C++ Debian VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by prateek urmaliya:
    Hi Anand,

    I have sent you a PM.


    I'll be damned -- don't have a clue! Quite wierd, I'll admit. Is there any reason you don't want to post the link to the image in the forum?

    Any case, there are a couple of things I would suggest you do.

    Since it is a small script, post its contents, especially its shebang line. Also please post the output of the following:
    .

    Of course, make sure whatever you post is kosher (both for yourself/your employer as well as for this forum).

    Sorry couldn't be of more help,
    - Anand
     
    Stefan Wagner
    Ranch Hand
    Posts: 1923
    Linux Postgres Database Scala
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Where is the script located?
    Sometimes, entire drives are mounted, but prohibited to execute commands there (typically: dos/windows partitions - vfat, ntfs).

    does

    work?
     
    prateek urmaliya
    Ranch Hand
    Posts: 87
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi All,

    well I commited gross mistake of editing the file in textpad and then uploading the file then I read #2,
    I used vi for creating new script and it run fine
    Thanks Ulf,Stefan,Ben and Anand (not in order of appearance)
    from now V is for vi,
    I am still wondering how worked ?
    I need to attend my UNIX 101 class again.
    Thanks Guys for your help.

    [ April 28, 2007: Message edited by: prateek urmaliya ]
    [ April 28, 2007: Message edited by: prateek urmaliya ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic