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 09-08-2011, 06:15 AM   #1
hvdosten
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Rep: Reputation: Disabled
sh - No such file or directory


Hi out there,

I try to start several programs (compiled with g77) in batch mode. It works, if I start each binary file manually, but with sh i receive the message "no such file or directory", which I don't understand.


So, in a directory there are three programs, named

~⁄Desktop/Programme/Magnetik/program1
~⁄Desktop/Programme/Magnetik/program2
~⁄Desktop/Programme/Magnetik/program3


and this is the sh script:

~⁄Desktop/Programme/Magnetik/program1
read -p "Press enter if ready" nothing
~/Users/meinmacbookpro/Desktop⁄Programme⁄Magnetik⁄program2
~/Users/meinmacbookpro/Desktop⁄Programme⁄Magnetik⁄program3



The output of this script is:

magnetik.sh: line 1: ~⁄Desktop/Programme/Magnetik/program1: No such file or directory
Press enter if ready



But, if I start the first line manually:

~/Desktop/Programme/Magnetik/program1
File ois.xyz created



if works.

Why? Where is the error?

Thanks a lot for any small hint
Harry
 
Old 09-08-2011, 06:38 AM   #2
adam999
Member
 
Registered: Sep 2006
Posts: 105

Rep: Reputation: 18
Have you tried the full path in the script without the ~
 
Old 09-08-2011, 06:45 AM   #3
hvdosten
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by adam999 View Post
Have you tried the full path in the script without the ~
yes, and again with no success.



But now, I have changed the line:

⁄Desktop/Programme/Magnetik

to

cd /Desktop
cd Programme
cd Magnetik


and then it works.



But if I change that line to:

cd /Desktop
cd Programme/Magnetik

I again receive the error message "no such file or directory".


I don't understand why...
 
Old 09-08-2011, 06:55 AM   #4
adam999
Member
 
Registered: Sep 2006
Posts: 105

Rep: Reputation: 18
Should the path be /home/Desktop ?
 
Old 09-08-2011, 07:04 AM   #5
hvdosten
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by adam999 View Post
Should the path be /home/Desktop ?
when I change to /home/Desktop, I get:

MacBook-Pro:gis meinmacbookpro$ sh magnetik.sh
magnetik.sh: line 1: cd: /home/Desktop/Programme/Magnetik: No such file or directory
 
Old 09-08-2011, 07:41 AM   #6
adam999
Member
 
Registered: Sep 2006
Posts: 105

Rep: Reputation: 18
So whats the full path then?

~⁄Desktop/Programme/Magnetik/

Or

~/Users/meinmacbookpro/Desktop⁄Programme⁄Magnetik⁄

Cd into the correct directory and type pwd (on the cli not in a shell script)
 
Old 09-08-2011, 07:44 AM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Are you using the right character encoding for the script file?
Kevin Barry
 
Old 09-08-2011, 07:59 AM   #8
hvdosten
LQ Newbie
 
Registered: Sep 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by adam999 View Post
So whats the full path then?

~⁄Desktop/Programme/Magnetik/

Or

~/Users/meinmacbookpro/Desktop⁄Programme⁄Magnetik⁄

Cd into the correct directory and type pwd (on the cli not in a shell script)



the path is:

~/Desktop/Programme/Magnetik and

/Users/meinmacbookpro/Desktop/Programme/Magnetik respecitvely

---------- Post added 09-08-11 at 12:59 PM ----------

Quote:
Originally Posted by ta0kira View Post
Are you using the right character encoding for the script file?
Kevin Barry


yes, Kevin, I think so...
 
Old 09-09-2011, 05:02 AM   #9
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
How do you start magnetik.sh on the command line? You can use the to get the full path:
Code:
sh -x magnetik.sh
 
Old 09-09-2011, 05:21 AM   #10
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Rep: Reputation: 41
How about adding this on your script?

Code:
#!/usr/bin/sh
Regards,
archieval
 
Old 09-09-2011, 05:29 AM   #11
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Quote:
Originally Posted by archieval View Post
How about adding this on your script?

Code:
#!/usr/bin/sh
Not on a Mac. There it is in /bin, not /usr/bin. But I think even between Linux distribution the location varies, as on openSUSE it’s in /bin too.

But sure, running the script on its own is feasible. Then it needs to be set to executable too:
Code:
chmod +x Magnetik.sh
 
  


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
chroot:cannot change root directory to: No such file directory janakiramulu Linux From Scratch 5 04-23-2011 01:00 AM
Get first file of directory then copy to other directory andd rename the file Faye Linux - Software 4 01-30-2011 09:16 AM
mkdir : cannot create directory : no such file or directory patcheezy Linux - Newbie 6 05-13-2009 11:26 AM
Copying a single file into each directory of a directory tree mlapl1 Linux - Newbie 2 06-27-2007 10:18 PM
How to protect a file/directory in your home login directory (RH Linux) jitsenho Linux - Security 9 07-03-2006 11:08 PM

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

All times are GMT -5. The time now is 10:02 PM.

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