If you mention the error "No such file or directory" is as it is, because your shell interpreter does not find the file or directory you wrote.
If you put something like:
$ mi_programa
Before a command is executed, a redirect is performed (with ""). Then following the sequence used by the shell, which is this.
Find the alias.
Parameter expansion, command substitution, arithmetic expansion and elimination of quotation marks before being assigned to the variable.
Check if it's a shell function mi_programa(){...}
Check if it's a BUILTIN.
Check if you are in the hash tables . hash | less
Check the PATH variable (if it does not find route elements in its command name)
If all else fails, the error message of the style "command not found" appears, which seems to be the error that appears to you.
Now, if we focus on point 6 of the order of execution, you have to have your command (or a symbolic link) mi_programa
in a folder in variable PATH
(revise with echo $PATH
) as long as This command has no route elements , which are '/', '.', '..'. If you have route elements, look for that route, for example.
$ ls -la
rwxrwxrwx 1 u1 u1 512 Nov 24 19:27 .
rwxrwxrwx 1 u1 u1 512 Nov 24 19:27 ..
rwxrwxrwx 1 u1 u1 512 Nov 24 19:27 mi_programa
$ pwd
/home/u1/carpeta1
$ /home/u1/carpeta1/mi_programa
(se ejecuta lo que tenga tu programa)
In this case, you executed your program because you wrote it with the route elements that are the diagonals' /'.
Now, in case you use the route elements like the point '.' or the two points '...' which are names that are linked with hard links to the folder itself and to its ancestor, respectively. In other simplistic words, '.' refers to the current folder and '..' to its ancestor. Then you can run your program in the same way with
$ ./mi_programa
Or with.
$ ../carpeta1/miprograma
They would have to do the same to you.
With these two things it should be enough to fix this problem, but I had to explain the entire preamble first to explain why the error message.
All this is assuming they have execution permissions. That is, if writing ls
to my_program, it has something of the style.
$ ls -la mi_programa
-r-xr-xr-x 1 u1 u1 25 Dec 18 21:59 mi_programa
# Con "r" de permisos de lectura (read) para que la shell lo pueda leer y con
# "x" de permisos de ejecución para que tu shell pueda permitir utilizarlo como
# ejecutable.
In case you do not have permissions, you can use something in one of the ways.
$ chmod a+x mi_programa
$ chmod u+x mi_programa
$ chmod +x mi_programa
$ chmod 755 mi_programa
But I doubt that I have this problem but I would give you an error of type "permission denied", but not "file not found".
Clarification with the shebang
What you did to change the shebang just changed the program that the shell would run with.
That is to say, when putting the first line #!/programa
you indicate to the shell with what program you are going to execute the content of that file.
For example. Suppose you have the files a1 and a2 in the same folder, a2 has as content.
contenido
de archivo a2
And in a1 you have this.
#!/bin/cat a2
Modifying the permissions so that it is executed.
$ chmod u+x a1
$ ./a1
contenido
de archivo a2
#!/bin/cat a2
Here, with the shebang of #!/bin/cat
you made use of the cat program. On the other hand, in the case of bash or sh, you use /bin/bash
and /bin/dash
, this is dash
, it is not a typo.
In other words, changing the shebang to your program does not affect anything if the error you throw is "No such file or directory".