0

Three examples what I type in bash command line after prompt and what are the responses:

'xxx' "aaa"

response:

bash: xxx: command not found

ok.

/bin/bash -c 'xxx'

response:

/bin/bash: line 1: xxx: command not found

ok.

/bin/bash -c 'xxx' "aaa"

response:

aaa: line 1: xxx: command not found

unexpainable.

It looks like if "aaa" would be the shell reporting this error.

It took me many days for searching what is the cause in my script.

Regards

Anton Wessel
  • 111
  • 9
  • 3
    What is your question? – DavidPostill Dec 26 '22 at 11:07
  • 1
    I fully support the above comment. And then: (1) Are you sure you did not use `bash -c`? (2) In case you really didn't, what is the content of `xxx`? – Kamil Maciorowski Dec 26 '22 at 18:29
  • 1
    Do these exact examples work as you say, or did you substitute the strings 'xxx' and "aaa" in place of the strings you were really using? If your examples aren't the real strings you were using, do the substitutes you used in your example work the same way for you as the real strings did? – Spiff Dec 27 '22 at 00:58
  • since for me "unexplainable" the question is: can someone explain. – Anton Wessel Dec 28 '22 at 12:28
  • For `bash -c`: yes, sure, I can. For `bash` without `-c` I cannot, I'm curious myself. Can you please respond to my first comment? – Kamil Maciorowski Dec 28 '22 at 12:39
  • to Kamil M. (1): of course I have used /bin/bash -c with -c. I have typed in by hand and this is a typo in my question, excuse me. I will edit now and correct. – Anton Wessel Dec 28 '22 at 12:40
  • Kamil M. 6 min ago: bin/bash -c 'xxx' "aaa" results in aaa: ...errormsg...Normally the first item in the error-message-line is the name of the process which reports the error, in my case should print "bash" or "/bin/bash". A need to have in order to be able to search for the error-message-line. Regards – Anton Wessel Dec 28 '22 at 12:55
  • If you need the name `bash` then replace `aaa` with `bash`. – Kamil Maciorowski Dec 28 '22 at 12:56
  • the 'xxx' means a name of a non-existing command in order bash to complain. Regards. – Anton Wessel Dec 28 '22 at 13:00
  • The "aaa" is a term in my script which must stay as is, cannot be replaced by the word "bash", for my question I have shortened it by "aaa" to mean "somerhing". The problem and core of my question is: why does in this case bash not beginn its error-message-line with "bash" or "/bin/bash" as it normally does. Is that a special feature of bash which I do not know in the moment or is it a bug in bash? Regards. – Anton Wessel Dec 28 '22 at 13:13
  • 1
    Sigh… I have closed your question as a duplicate of [my question](https://superuser.com/q/1526229/432690) because [my answer there](https://superuser.com/a/1526230/432690) explains exactly these things, it tells what to do, what not to do. **Have you read it?** If you need `bash -c` to name itself `bash`, do not use `bash -c '… "$0" …' aaa`. Use `bash -c '… "$1" …' bash aaa`. Weeks ago [I gave you the same link](https://unix.stackexchange.com/q/726902/108618#comment1378783_726902). – Kamil Maciorowski Dec 28 '22 at 13:22
  • 1
    Anton, see `man bash` and the explanation of `-c` in the first few paragraphs (especially the part relating to how `$0` is set). So whatever you pass as `aaa` will end up in `$0`, it has no other effect. – nohillside Dec 28 '22 at 13:26
  • 1
    Ditto. My answer to the linked question quotes *this very fragment* of `man bash`. – Kamil Maciorowski Dec 28 '22 at 13:35
  • to Kamil Maciorowski: Very many thanks for your given link. Thanks to this link I have read your very important basics-article. My case is in relation to xargs, which often forces to use /bin/bash -c '...'. After having learned from your article, in future I will always use: /bin/bash 'echo "$1" ' "dummy" "aaa". I wll correct all my scripts. --- Hopefully these commets will not go lost, thus others can read it. --- Thanks, Regards. – Anton Wessel Dec 29 '22 at 10:26

0 Answers0