:: Re: [DNG] bash / quote weirdness
Top Page
Delete this message
Reply to this message
Author: Olaf Meeuwissen
Date:  
To: Steve Litt
CC: dng
Subject: Re: [DNG] bash / quote weirdness
Hi,

Steve Litt <slitt@???> 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.

>      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


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 Meeuwissen                    FSF Associate Member since 2004-01-27
 GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13  F43E B8A4 A88A F84A 2DD9
 Support Free Software                        https://my.fsf.org/donate
 Join the Free Software Foundation              https://my.fsf.org/join