Partage
  • Partager sur Facebook
  • Partager sur Twitter

C/Linux, chemins de fichiers invalides...

...selon la façon dont je lance le programme

Sujet résolu
7 septembre 2011 à 16:52:48

@Maëlan: il me semble que ce que dit ton lien c'est que pour exéuter un fichier situé dans le répertoire courant, il est nécessaire de le précéder de ./. Donc, par exemple: ./fichier.

Par contre, il ne dit pas qu'il faut précéder un chemin relatif de ./ ;)
  • Partager sur Facebook
  • Partager sur Twitter
7 septembre 2011 à 16:59:58

Hmm hmm... J'ai lu un peu vite alors, que le grand Gégène m'aplatisse. :honte:

ÉDIT : En effet, cela marche chez moi. La vérité serait donc « Un chemin relatif contient au moins un caractère '/' (barre oblique). ».
  • Partager sur Facebook
  • Partager sur Twitter
8 septembre 2011 à 11:25:03

Citation : Maëlan

Note bien qu'il est dit "en général". M'est avis que c'est ton shell qui est plus exotique. :-°


Mon shell est des plus courant (bash).
En fait, tu interprètes mal ce que tu lis. Le texte de Wikipédia parle du répertoire courant. Mais quand on tape foo/bar, on lance un fichier du répertoire foo, pas du répertoire courant.
Enfin, le mieux est encore de lire la documentation officielle

Citation : http://www.gnu.org/s/bash/manual/bash.html#Command-Search-and-Execution


3.7.2 Command Search and Execution



After a command has been split into words, if it results in a simple command and an optional list of arguments, the following actions are taken.

If the command name contains no slashes, the shell attempts to locate it. If there exists a shell function by that name, that function is invoked as described in Shell Functions.
If the name does not match a function, the shell searches for it in the list of shell builtins. If a match is found, that builtin is invoked.
If the name is neither a shell function nor a builtin, and contains no slashes, Bash searches each element of $PATH for a directory containing an executable file by that name. Bash uses a hash table to remember the full pathnames of executable files to avoid multiple PATH searches (see the description of hash in Bourne Shell Builtins). A full search of the directories in $PATH is performed only if the command is not found in the hash table. If the search is unsuccessful, the shell searches for a defined shell function named command_not_found_handle. If that function exists, it is invoked with the original command and the original command's arguments as its arguments, and the function's exit status becomes the exit status of the shell. If that function is not defined, the shell prints an error message and returns an exit status of 127.
If the search is successful, or if the command name contains one or more slashes, the shell executes the named program in a separate execution environment. Argument 0 is set to the name given, and the remaining arguments to the command are set to the arguments supplied, if any.

  • Partager sur Facebook
  • Partager sur Twitter