Re: [DNG] bash / quote weirdness

2022-01-14 Thread Steve Litt
Benjamin Riefenstahl said on Fri, 14 Jan 2022 10:33:29 +0100

>Hi Steve,
>
>> Benjamin Riefenstahl said on Thu, 13 Jan 2022 18:19:23 +0100  
>>>Different code paths within Bash.  [...]  
>
>Steve Litt writes:
>> This is true, but not the explanation for this particular behavior,
>> as follows:
>>
>> [slitt@mydesk ~]$ /usr/bin/cat -n /etc/fstab | cut -b 1-20 | head -n5
>>  1   UUID=730eaf92
>>  2   UUID=41abb5fd
>>  3   UUID=96cfdfb3
>>  4   UUID=6F66-BF7
>>  5   tmpfs /tmp tm
>> [slitt@mydesk ~]$ "/usr/bin/cat -n" /etc/fstab | cut -b 1-20 | head
>> -n5 bash: /usr/bin/cat -n: No such file or directory
>> [slitt@mydesk ~]$ "/usr/bin/cat -n /etc/fstab" | cut -b 1-20 | head
>> -n5 bash: /usr/bin/cat -n /etc/fstab: No such file or directory
>> [slitt@mydesk ~]$  
>
>I'm sorry, but I don't see it?  Can you point out what is suprising to
>you here?  Both commands contain "/", and both give the same error
>message.
>
>so long, benny

I thought you were saying that the cause of "cat -n" /etc/fstab being
seen as one command was due to cat not having a full path, so I put a
full path in front of it. If you weren't saying lack of a full path is
the cause of "cat -n" being considered a single command, then my
prepending the full path produces no surprise at all.


SteveT

Steve Litt 
Spring 2021 featured book: Troubleshooting Techniques of the Successful
Technologist http://www.troubleshooters.com/techniques
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-14 Thread Olaf Meeuwissen via Dng
Hi,

Steve Litt  writes:

> Benjamin Riefenstahl said on Thu, 13 Jan 2022 18:19:23 +0100
>
>>Hi Steve,
>>
>>Steve Litt writes:
>>> [slitt@mydesk ~]$ "cat -n" /etc/fstab | cut -b 1-20 |  head -n5
>>> bash: cat -n: command not found
>>> [slitt@mydesk ~]$ "cat -n /etc/fstab" | cut -b 1-20 |  head -n5
>>> bash: cat -n /etc/fstab: No such file or directory
>>> [slitt@mydesk ~]$
>>
>>Different code paths within Bash.  When there is a "/" in the command
>>name, that is a file that has to exist by that exact name (the file
>>name can be relative, though).  When there is no "/", then and only
>>then the command is searched along $PATH, and if it is not found
>>there, the error message is different from the other case.
>
> This is true, but not the explanation for this particular behavior, as
> follows:
>
> [slitt@mydesk ~]$ /usr/bin/cat -n /etc/fstab | cut -b 1-20 | head -n5

Here your shell look for a file called "cat" i /usr/bin.

>  1UUID=730eaf92
>  2UUID=41abb5fd
>  3UUID=96cfdfb3
>  4UUID=6F66-BF7
>  5tmpfs /tmp tm
> [slitt@mydesk ~]$ "/usr/bin/cat -n" /etc/fstab | cut -b 1-20 | head -n5

Here your shell looks for a file called "cat -n" in /usr/bin.

> bash: /usr/bin/cat -n: No such file or directory
> [slitt@mydesk ~]$ "/usr/bin/cat -n /etc/fstab" | cut -b 1-20 | head -n5

Here your shell looks for a file called "fstab" in a directory called
"etc" in a directory called "cat -n " in /usr/bin.

> bash: /usr/bin/cat -n /etc/fstab: No such file or directory

Given that, I believe Benjamini's explanation still holds.

Hope this helps,
--
Olaf MeeuwissenFSF Associate Member since 2004-01-27
 GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13  F43E B8A4 A88A F84A 2DD9
 Support Free Softwarehttps://my.fsf.org/donate
 Join the Free Software Foundation  https://my.fsf.org/join
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-14 Thread Benjamin Riefenstahl
Hi Steve,

> Benjamin Riefenstahl said on Thu, 13 Jan 2022 18:19:23 +0100
>>Different code paths within Bash.  [...]

Steve Litt writes:
> This is true, but not the explanation for this particular behavior, as
> follows:
>
> [slitt@mydesk ~]$ /usr/bin/cat -n /etc/fstab | cut -b 1-20 | head -n5
>  1UUID=730eaf92
>  2UUID=41abb5fd
>  3UUID=96cfdfb3
>  4UUID=6F66-BF7
>  5tmpfs /tmp tm
> [slitt@mydesk ~]$ "/usr/bin/cat -n" /etc/fstab | cut -b 1-20 | head -n5
> bash: /usr/bin/cat -n: No such file or directory
> [slitt@mydesk ~]$ "/usr/bin/cat -n /etc/fstab" | cut -b 1-20 | head -n5
> bash: /usr/bin/cat -n /etc/fstab: No such file or directory
> [slitt@mydesk ~]$

I'm sorry, but I don't see it?  Can you point out what is suprising to
you here?  Both commands contain "/", and both give the same error
message.

so long, benny
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-13 Thread Steve Litt
Hendrik Boom said on Thu, 13 Jan 2022 18:15:28 -0500

>On Thu, Jan 13, 2022 at 12:45:09PM -0500, . via Dng wrote:
>
>> 
>> The shell receives a series of tokens, and tries to interpret the
>> first one as a command.  In the double-quoted attempt above, it gets
>> two tokens before the first pipe | ---
>> 
>>     1) "cat -n"
>> 
>>     2) /etc/fstab
>> 
>> Of course, the system has no command named "cat -n".  (And only a
>> chaotic evil person would use a space in a command's name.)
>> Something like "cat"  "-n"  /etc/fstab  
>
>Maybe to keep anyone from executing a potentially danterous command by
>mistake?

Yeah, that too.

SteveT

Steve Litt 
Spring 2021 featured book: Troubleshooting Techniques of the Successful
Technologist http://www.troubleshooters.com/techniques
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-13 Thread Steve Litt
. via Dng said on Thu, 13 Jan 2022 12:45:09 -0500


>The shell receives a series of tokens, and tries to interpret the
>first one as a command.  In the double-quoted attempt above, it gets
>two tokens before the first pipe | ---
>
>     1) "cat -n"
>
>     2) /etc/fstab
>
>Of course, the system has no command named "cat -n".  (And only a 
>chaotic evil person would use a space in a command's name.) Something
>like
>     "cat"  "-n"  /etc/fstab
>
>would work fine, the shell now sees three tokens (and the double
>quotes are completely unnecessary here), and the first is recognized
>as a command that's on the executable path.
>
>The same goes for "cat /etc/fstab" or "cat fstab", they're both just 
>text strings that happen to include a space character.
 ^^
 dng is correct!


SteveT

Steve Litt 
Spring 2021 featured book: Troubleshooting Techniques of the Successful
Technologist http://www.troubleshooters.com/techniques
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-13 Thread Steve Litt
Benjamin Riefenstahl said on Thu, 13 Jan 2022 18:19:23 +0100

>Hi Steve,
>
>Steve Litt writes:
>> [slitt@mydesk ~]$ "cat -n" /etc/fstab | cut -b 1-20 |  head -n5
>> bash: cat -n: command not found
>> [slitt@mydesk ~]$ "cat -n /etc/fstab" | cut -b 1-20 |  head -n5
>> bash: cat -n /etc/fstab: No such file or directory
>> [slitt@mydesk ~]$  
>
>Different code paths within Bash.  When there is a "/" in the command
>name, that is a file that has to exist by that exact name (the file
>name can be relative, though).  When there is no "/", then and only
>then the command is searched along $PATH, and if it is not found
>there, the error message is different from the other case.

This is true, but not the explanation for this particular behavior, as
follows:

[slitt@mydesk ~]$ /usr/bin/cat -n /etc/fstab | cut -b 1-20 | head -n5
 1  UUID=730eaf92
 2  UUID=41abb5fd
 3  UUID=96cfdfb3
 4  UUID=6F66-BF7
 5  tmpfs /tmp tm
[slitt@mydesk ~]$ "/usr/bin/cat -n" /etc/fstab | cut -b 1-20 | head -n5
bash: /usr/bin/cat -n: No such file or directory
[slitt@mydesk ~]$ "/usr/bin/cat -n /etc/fstab" | cut -b 1-20 | head -n5
bash: /usr/bin/cat -n /etc/fstab: No such file or directory
[slitt@mydesk ~]$

SteveT

Steve Litt 
Spring 2021 featured book: Troubleshooting Techniques of the Successful
Technologist http://www.troubleshooters.com/techniques
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-13 Thread Antony Stone
On Friday 14 January 2022 at 00:15:28, Hendrik Boom wrote:

> On Thu, Jan 13, 2022 at 12:45:09PM -0500, . via Dng wrote:
> > The shell receives a series of tokens, and tries to interpret the first
> > one as a command.  In the double-quoted attempt above, it gets two
> > tokens before the first pipe | ---
> > 
> > 1) "cat -n"
> > 
> > 2) /etc/fstab
> > 
> > Of course, the system has no command named "cat -n".  (And only a chaotic
> > evil person would use a space in a command's name.) Something like
> > "cat"  "-n"  /etc/fstab
> 
> Maybe to keep anyone from executing a potentially dangerous command by
> mistake?

That doesn't sound like the standard *nix approach to me.

Antony.

-- 
"There is no reason for any individual to have a computer in their home."

 - Ken Olsen, President of Digital Equipment Corporation (DEC, later consumed 
by Compaq, later merged with HP)

   Please reply to the list;
 please *don't* CC me.
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-13 Thread Hendrik Boom
On Thu, Jan 13, 2022 at 12:45:09PM -0500, . via Dng wrote:

> 
> The shell receives a series of tokens, and tries to interpret the first one
> as a command.  In the double-quoted attempt above, it gets two tokens before
> the first pipe | ---
> 
>     1) "cat -n"
> 
>     2) /etc/fstab
> 
> Of course, the system has no command named "cat -n".  (And only a chaotic
> evil person would use a space in a command's name.) Something like
>     "cat"  "-n"  /etc/fstab

Maybe to keep anyone from executing a potentially danterous command by mistake?

-- hendrik

> would work fine, the shell now sees three tokens (and the double quotes are
> completely unnecessary here), and the first is recognized as a command
> that's on the executable path.
> 
> The same goes for "cat /etc/fstab" or "cat fstab", they're both just text
> strings that happen to include a space character.
> 
> 
> ___
> Dng mailing list
> Dng@lists.dyne.org
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-13 Thread . via Dng


On Wed, 2022-01-12 at 00:08 +0100, Florian Zieboll via Dng wrote:

Dear list,

this im my 'test.sh':

#!/bin/bash
for f in "$@" ; do
 xcmd="unrar x"
 $xcmd "$f"
done

Can please somebody explain, why, if I double-quote the "$xcmd"
variable in line 4, the script fails with

./test.sh: line 4: unrar x: command not found

???

Commands without parameters resp. whitespace (e.g. xcmd="unzip") work
fine when double-quoted; a web search (including the "GNU Bash
manual"
[1]) did not shed any light on this mystery...

Thank you and libre Grüße,
Florian


--

Message: 2
Date: Thu, 13 Jan 2022 09:07:22 -0500
From: Hendrik Boom 
To: dng@lists.dyne.org
Subject: Re: [DNG] [OT] bash / quote weirdness
Message-ID: <20220113140722.ga30...@topoi.pooq.com>
Content-Type: text/plain; charset=us-ascii

On Wed, Jan 12, 2022 at 05:45:08PM -0500, Steve Litt wrote:
On the other hand...

===
[slitt@mydesk ~]$ cat -n /etc/fstab | cut -b 1-20 |  head -n5
  1 UUID=730eaf92
  2 UUID=41abb5fd
  3 UUID=96cfdfb3
  4 UUID=6F66-BF7
  5 tmpfs /tmp tm
[slitt@mydesk ~]$ "cat -n" /etc/fstab | cut -b 1-20 |  head -n5
bash: cat -n: command not found
[slitt@mydesk ~]$ "cat -n /etc/fstab" | cut -b 1-20 |  head -n5
bash: cat -n /etc/fstab: No such file or directory
[slitt@mydesk ~]$

So if it has parameters it's a command, and if it diesn't it's just
a file or directory?

-- hendrik


--

Message: 3
Date: Thu, 13 Jan 2022 15:43:29 +0100
From: Antony Stone 
To: dng@lists.dyne.org
Subject: Re: [DNG] [OT] bash / quote weirdness
Message-ID: <202201131543.29980.antony.st...@devuan.open.source.it>
Content-Type: Text/Plain;  charset="utf-8"

On Thursday 13 January 2022 at 15:07:22, Hendrik Boom wrote:


On Wed, Jan 12, 2022 at 05:45:08PM -0500, Steve Litt wrote:

[slitt@mydesk ~]$ cat -n /etc/fstab | cut -b 1-20 |  head -n5

  1 UUID=730eaf92
  2 UUID=41abb5fd
  3 UUID=96cfdfb3
  4 UUID=6F66-BF7
  5 tmpfs /tmp tm

[slitt@mydesk ~]$ "cat -n" /etc/fstab | cut -b 1-20 |  head -n5
bash: cat -n: command not found

[slitt@mydesk ~]$ "cat -n /etc/fstab" | cut -b 1-20 |  head -n5
bash: cat -n /etc/fstab: No such file or directory

So if it has parameters it's a command, and if it diesn't it's just
a file or directory?

It looks a good deal more complicated than that...

$ "cat /etc/fstab"
bash: cat /etc/fstab: No such file or directory

$ "cat fstab"
bash: cat fstab: command not found

I have no idea what's really going on here.


Antony.


The shell receives a series of tokens, and tries to interpret the first 
one as a command.  In the double-quoted attempt above, it gets two 
tokens before the first pipe | ---


    1) "cat -n"

    2) /etc/fstab

Of course, the system has no command named "cat -n".  (And only a 
chaotic evil person would use a space in a command's name.) Something like

    "cat"  "-n"  /etc/fstab
would work fine, the shell now sees three tokens (and the double quotes 
are completely unnecessary here), and the first is recognized as a 
command that's on the executable path.


The same goes for "cat /etc/fstab" or "cat fstab", they're both just 
text strings that happen to include a space character.



___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng


Re: [DNG] bash / quote weirdness

2022-01-13 Thread Benjamin Riefenstahl
Hi Steve,

Steve Litt writes:
> [slitt@mydesk ~]$ "cat -n" /etc/fstab | cut -b 1-20 |  head -n5
> bash: cat -n: command not found
> [slitt@mydesk ~]$ "cat -n /etc/fstab" | cut -b 1-20 |  head -n5
> bash: cat -n /etc/fstab: No such file or directory
> [slitt@mydesk ~]$

Different code paths within Bash.  When there is a "/" in the command
name, that is a file that has to exist by that exact name (the file name
can be relative, though).  When there is no "/", then and only then the
command is searched along $PATH, and if it is not found there, the error
message is different from the other case.

At least that is my explanation.

so long, benny
___
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng