Visit Our UNIX and Linux User Community


No Such File or Directory error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting No Such File or Directory error
# 1  
Old 01-24-2014
No Such File or Directory error

Hi! I just recently started messing around with Unix, but I've come upon one problem multiple times. Whenever I try to run a shell script, for example;

Code:
#! /bin/bash 
#-------------------------------------- 
# example1 
#-------------------------------------- 
echo "Hello, World!"

I always get the error:

Code:
: No such file or directory

The file is in the correct directory, I've verified that with ls -l, I've also used chmod 700 example1, to give myself permissions to execute the shell, but I just keep getting the same problem. Thanks for any help!

Last edited by SoapilyProne; 01-24-2014 at 07:07 PM..
# 2  
Old 01-24-2014
As it is probably not in the path ensure......

Assuming it is executable:-

1) chmod 755 /full/path/to/filename.ext<CR>
2) use one of two methods to run it:-
A) /full/path/to/filename.ext<CR>
B) ./filename.ext<CR>
From the current directory/drawer/folder.
<CR> is the carriage return or enter key...

EDIT:
Note in your script the first line should read:-
Code:
#!/bin/bash

No space at all in the line.

Last edited by wisecracker; 01-24-2014 at 07:12 PM.. Reason: See above...
# 3  
Old 01-24-2014
Can you post what exactly you did?

Set xtrace / verbose and run your script and post the output.
Code:
#!/bin/bash -xv

As wisecracker said, current working directory will not be part of PATH and it is not supposed to be.

So execute your script like he posted.
# 4  
Old 01-24-2014
It's not the spacing in the shebang.

Code:
$ echo $'#! /bin/bash\necho hello world\n' > file; chmod a+x file; ./file
hello world

But perhaps this: (Different OS/shell would produce different error. This is from Linux & Bash)

Code:
$ echo $'#! /bin/bash\r\necho hello world\n' > file; chmod a+x file; ./file
-bash: ./file: /bin/bash^M: bad interpreter: No such file or directory
$ sh
$ ./file
sh: 4: ./file: not found

Did you create the file in Windows? You need to remove the Windows line endings. This is just one of many ways:

Code:
tr -d '\r' < file > newfile


Last edited by neutronscott; 01-25-2014 at 03:15 AM..
# 5  
Old 01-24-2014
I created the file in Windows and then uploaded the file to a Unix timeshare.
# 6  
Old 01-25-2014
Hi neutronscott et al...
Just for information purposes...
OSX 10.7.5 default bash terminal...
Code:
Last login: Sat Jan 25 09:46:55 on ttys000
AMIGA:barrywalker~> echo "text" > testtxt
AMIGA:barrywalker~> cd ..
AMIGA:barrywalker/Users> ./testtxt
-bash: ./testtxt: No such file or directory
AMIGA:barrywalker/Users> _


Previous Thread | Next Thread
Test Your Knowledge in Computers #798
Difficulty: Medium
To convert from a base-10 integer to its base-2 (binary) equivalent, the number is divided by two and the remainder is the least-significant bit.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

No such file or directory error

I am new to shell scripting so I assume there is something basic I am missing but I have not been able to figure it out. When I run the following code from a script it can't find the paths to the directory or files. I can literally cut and paste the commands into terminal and they work fine. Why... (2 Replies)
Discussion started by: TryAgain12
2 Replies

2. Shell Programming and Scripting

Weird Error (: No such file or directory)

Hi Everyone, I am trying to make this script to use, to find out the DAHDI channel status. Every thing works fine, I even get proper results, however I have this weird error that comes along. Can someone please help me. Thanks a lot. #!/bin/bash # Color to set the test to when a channel is... (3 Replies)
Discussion started by: jeetz
3 Replies

3. Solaris

/bin/find: stat() error <File> : No such file or directory

Hi, I am getting below error in Solaris 10 SPARC when trying to issue a search on /var/tmp partition Below is the query /bin/find /var/tmp/ -type f -atime +1 Below is the result /bin/find: stat() error <File> : No such file or directory (28 Replies)
Discussion started by: prash358
28 Replies

4. Shell Programming and Scripting

No such file or directory error

Hi, After executing load_data.sh script , it completes the steps in script but give following error.Please let me know how to fix it. ./load_data.sh: ' missing ./load_data.sh: 0: not found for i in 1 2 3 do ###some processing#### DLOG=$( eval echo \${TXPCY_${i}_DATA_FILE_LOG} )... (4 Replies)
Discussion started by: sandy162
4 Replies

5. Shell Programming and Scripting

Error : No such file or directory

Hi, I have issued the below command to remove directories under a specific path, it removes them fine. But atlast it tries to find the same directory and fails. Directories: /root/app/dir /root/app/dir/files/ /root/app/dir/backup/ /root/app/dir/archive/ Command: find... (1 Reply)
Discussion started by: vel4ever
1 Replies

6. UNIX for Dummies Questions & Answers

SCP error: No such file or directory

Hi, I am trying to do scp using the following script: #!/usr/local/bin/bash BUILDDATE=20120220 for line in `cat arch_host_plat_src_dest` do src=`echo $line | cut -d: -f4` dest=`echo $line | cut -d: -f5` echo scp -p /builds/${BUILDDATE}/Integration/$src ... (1 Reply)
Discussion started by: Technext
1 Replies

7. UNIX for Dummies Questions & Answers

Error: GL/glut.h: No such file or directory

hi, I get this error when I compile my source on mac Leopard. is because I need to configure openGL path ? Monitor.h:15:60: error: GL/glut.h: No such file or directory Monitor.h:16:60: error: GL/gl.h: No such file or directory Monitor.C: In function 'void display2()': Monitor.C:77:... (0 Replies)
Discussion started by: aneuryzma
0 Replies

8. Linux

Error crt0.o no such file or directory

Hi, I am installing gcc cross compiler for x86_64. After installation when i am compiling simple program, i am getting error as "/usr/cross/lib/gcc-lib/x86_64-pc-elf/3.2.3/../../../../x86_64-pc-elf/bin/ld: cannot open crt0.o: No such file or directory" Please tell me how to resolve this... (1 Reply)
Discussion started by: Mandar123
1 Replies

9. UNIX for Dummies Questions & Answers

SFTP error: no such file or directory

Hi All, I am using a shell script for SFTPing the files to target server. The problem which I am facing is that even if the files are not transferred, the script finishes successfully. I want the script to fail in case the remote directory does not exists. The script which I am using is as... (1 Reply)
Discussion started by: shalini@@@
1 Replies

10. Linux

error: rw/regexp.h: No such file or directory

Hello every one, i am trying to compile c++ modules. while compiling a module i am getting the following error. cdbh_RecordStore.C:32:23: error: rw/regexp.h: No such file or directory make: *** Error 1 I googled for the solution , i found that this is a Rogue wave class. actually... (0 Replies)
Discussion started by: mannam srinivas
0 Replies

Featured Tech Videos