Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Klingon phaser attack from front!!!!! 100% Damage to life support!!!!


devel / comp.unix.shell / Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

SubjectAuthor
* bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target plachongy...@gmail.com
+* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onJanis Papanagnou
|+* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target hongy...@gmail.com
||+* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target Kees Nuyt
|||`- Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onhongy...@gmail.com
||`* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onJanis Papanagnou
|| `- Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onJanis Papanagnou
|`* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onhongy...@gmail.com
| `* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onhongy...@gmail.com
|  `* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onJanis Papanagnou
|   +* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onDavid W. Hodgins
|   |`* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onhongy...@gmail.com
|   | `* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onDavid W. Hodgins
|   |  +* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onOğuz
|   |  |+* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target Keith Thompson
|   |  ||`- Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onOğuz
|   |  |`* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target Helmut Waitzmann
|   |  | `* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target Keith Thompson
|   |  |  `- Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target Helmut Waitzmann
|   |  `* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onJanis Papanagnou
|   |   `- Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onChris Elvidge
|   `* Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target Keith Thompson
|    `- Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff onJanis Papanagnou
`- Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuffLew Pitcher

1
bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4661&group=comp.unix.shell#4661

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:ac8:5c16:: with SMTP id i22mr24209611qti.313.1638581593089; Fri, 03 Dec 2021 17:33:13 -0800 (PST)
X-Received: by 2002:a05:6214:2021:: with SMTP id 1mr23113283qvf.75.1638581592935; Fri, 03 Dec 2021 17:33:12 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Fri, 3 Dec 2021 17:33:12 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.82.180; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.82.180
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
Subject: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sat, 04 Dec 2021 01:33:13 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 38
 by: hongy...@gmail.com - Sat, 4 Dec 2021 01:33 UTC

werner@X10DAi-00:~$ ls ~/Desktop/
Downloads.idm.wine "Newton's Principia for The Common Reader.djvu"
File.com.qq.weixin.deepin work
FileRecv.com.qq.im.deepin 霍金_时间简史.pdf

werner@X10DAi-00:~$ bash -c "cd '$1' && ls " -- ~/Desktop/
Desktop Mail PycharmProjects vmware
Documents Music README.md Yozo_Officelog.txt
Downloads News Templates Zotero
go Pictures texmf
hs_err_pid2195649.log Public Videos

werner@X10DAi-00:~$ bash -c "cd \$1 && ls " -- ~/Desktop/
Downloads.idm.wine "Newton's Principia for The Common Reader.djvu"
File.com.qq.weixin.deepin work
FileRecv.com.qq.im.deepin 霍金_时间简史.pdf

werner@X10DAi-00:~$ bash -c 'cd "$1" && ls' -- ~/Desktop/
Downloads.idm.wine "Newton's Principia for The Common Reader.djvu"
File.com.qq.weixin.deepin work
FileRecv.com.qq.im.deepin 霍金_时间简史.pdf

As you can see, the following two commands works as expected:

$ bash -c "cd \$1 && ls " -- ~/Desktop/
$ bash -c 'cd "$1" && ls' -- ~/Desktop/

But the following one doesn't:

$ bash -c "cd '$1' && ls " -- ~/Desktop/

Why does bash shell exhibit this behavior?

Regards,
HZ

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<soej4h$d76$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4662&group=comp.unix.shell#4662

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Sat, 4 Dec 2021 03:17:53 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <soej4h$d76$1@dont-email.me>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 4 Dec 2021 02:17:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f4b7d5f5e6feb2f9c33441a689ddba94";
logging-data="13542"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MEnOhcWCXeWJC2OSCTC5B"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:FH5J3kcDjnfMMfaQPBzWVxbYfa4=
In-Reply-To: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sat, 4 Dec 2021 02:17 UTC

On 04.12.2021 02:33, hongy...@gmail.com wrote:
>
> As you can see, the following two commands works as expected:

In my book, all work as expected.

>
> $ bash -c "cd \$1 && ls " -- ~/Desktop/
> $ bash -c 'cd "$1" && ls' -- ~/Desktop/
>
> But the following one doesn't:
>
> $ bash -c "cd '$1' && ls " -- ~/Desktop/
>
> Why does bash shell exhibit this behavior?

What behaviour; that $1 gets expanded on the outer shell level
[as expected]?

Because the expression passed to bash -c is double quoted and
thus variables like $1 will get expanded; the bash -c call
gets an expanded argument as parameter.

Why don't you try shell basics like shell quoting in simple
examples instead of trying to write complex shell programs?
It's so simple to check...

set wow
bash -c "echo '$1'"
bash -c "echo \$1"
bash -c 'echo "$1"'

Then what happens if you cd "" to an empty directory string?
That seems to depend on the shell. I think it should fail with
ENOENT (if I read POSIX correctly).

In any way you should avoid such potential errors by using the
correct quoting and guarantee the variables to get expanded as
intended.

Janis

>
> Regards,
> HZ
>

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<83398d9c-d5ee-4808-ac9e-315763f39702n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4663&group=comp.unix.shell#4663

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:4107:: with SMTP id j7mr21210971qko.645.1638588830652; Fri, 03 Dec 2021 19:33:50 -0800 (PST)
X-Received: by 2002:ad4:596d:: with SMTP id eq13mr24089317qvb.91.1638588830505; Fri, 03 Dec 2021 19:33:50 -0800 (PST)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Fri, 3 Dec 2021 19:33:50 -0800 (PST)
In-Reply-To: <soej4h$d76$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=143.198.81.128; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 143.198.81.128
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com> <soej4h$d76$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <83398d9c-d5ee-4808-ac9e-315763f39702n@googlegroups.com>
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sat, 04 Dec 2021 03:33:50 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 44
 by: hongy...@gmail.com - Sat, 4 Dec 2021 03:33 UTC

On Saturday, December 4, 2021 at 10:17:58 AM UTC+8, Janis Papanagnou wrote:
> On 04.12.2021 02:33, hongy...@gmail.com wrote:
> >
> > As you can see, the following two commands works as expected:
> In my book, all work as expected.
> >
> > $ bash -c "cd \$1 && ls " -- ~/Desktop/
> > $ bash -c 'cd "$1" && ls' -- ~/Desktop/
> >
> > But the following one doesn't:
> >
> > $ bash -c "cd '$1' && ls " -- ~/Desktop/
> >
> > Why does bash shell exhibit this behavior?
> What behaviour; that $1 gets expanded on the outer shell level
> [as expected]?
>
> Because the expression passed to bash -c is double quoted and
> thus variables like $1 will get expanded; the bash -c call
> gets an expanded argument as parameter.
>
> Why don't you try shell basics like shell quoting in simple
> examples instead of trying to write complex shell programs?
> It's so simple to check...
>
> set wow
> bash -c "echo '$1'"
> bash -c "echo \$1"
> bash -c 'echo "$1"'

werner@X10DAi-00:~$ set wow
werner@X10DAi-00:~$ bash -c "echo '$1'"
wow
werner@X10DAi-00:~$ bash -c "echo \$1"

werner@X10DAi-00:~$ bash -c 'echo "$1"'

werner@X10DAi-00:~$


> Then what happens if you cd "" to an empty directory string?
> That seems to depend on the shell. I think it should fail with
> ENOENT (if I read POSIX correctly).

What do you mean by saying ENOENT?

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<3plmqgtnsg1giop0vbivdjtqjr1g6a8fbs@dim53.demon.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4664&group=comp.unix.shell#4664

  copy link   Newsgroups: comp.unix.shell
From: k.n...@nospam.demon.nl (Kees Nuyt)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.
Date: Sat, 04 Dec 2021 12:59:48 +0100
Reply-To: k.nuyt@nospam.demon.nl
Message-ID: <3plmqgtnsg1giop0vbivdjtqjr1g6a8fbs@dim53.demon.nl>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com> <soej4h$d76$1@dont-email.me> <83398d9c-d5ee-4808-ac9e-315763f39702n@googlegroups.com>
User-Agent: ForteAgent/7.10.32.1214
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!abe006.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 46
Injection-Date: Sat, 04 Dec 2021 12:59:48 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1909
 by: Kees Nuyt - Sat, 4 Dec 2021 11:59 UTC

On Fri, 3 Dec 2021 19:33:50 -0800 (PST), "hongy...@gmail.com"
<hongyi.zhao@gmail.com> wrote:

> What do you mean by saying ENOENT?

Install the script named "ddg" below in a directory in your
path, and chmod +x /path/to/ddg ,
then type at the shell prompt:

$ ddg ENOENT

----- start of script ddg -----
#!/usr/bin/perl
# # quickly search duck duck go from command line
# # From: Eli the Bearded <*@eli.users.panix.com>
# Newsgroups: comp.misc
# Date: Mon, 12 Apr 2021 17:46:51 +0000 (UTC)

use strict;
use warnings;

my $browser = 'lynx';
my @browser_args = qw(
-useragent=Lynx/2.8.9rel.1
-image_links
-noreferer
-accept_all_cookies
-cookie_save_file=/dev/null
);
my $query = join('+',@ARGV);
my $base = 'https://duckduckgo.com/lite/';

if(defined($query) and $query ne '') {
$base .= "?q=$query";
}

push(@browser_args, $base);

exec($browser, @browser_args);
----- end of script ddg -----
--
Regards,
Kees Nuyt

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<ea8ec080-8238-441d-8995-27460fab2653n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4665&group=comp.unix.shell#4665

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:14cd:: with SMTP id u13mr27443938qtx.627.1638626183963;
Sat, 04 Dec 2021 05:56:23 -0800 (PST)
X-Received: by 2002:a05:620a:290c:: with SMTP id m12mr22746266qkp.571.1638626183806;
Sat, 04 Dec 2021 05:56:23 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 4 Dec 2021 05:56:23 -0800 (PST)
In-Reply-To: <3plmqgtnsg1giop0vbivdjtqjr1g6a8fbs@dim53.demon.nl>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.154; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.154
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me> <83398d9c-d5ee-4808-ac9e-315763f39702n@googlegroups.com>
<3plmqgtnsg1giop0vbivdjtqjr1g6a8fbs@dim53.demon.nl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ea8ec080-8238-441d-8995-27460fab2653n@googlegroups.com>
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Sat, 04 Dec 2021 13:56:23 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 51
 by: hongy...@gmail.com - Sat, 4 Dec 2021 13:56 UTC

On Saturday, December 4, 2021 at 7:59:54 PM UTC+8, Kees Nuyt wrote:
> On Fri, 3 Dec 2021 19:33:50 -0800 (PST), "hongy...@gmail.com"
> <hongy...@gmail.com> wrote:
>
> > What do you mean by saying ENOENT?
> Install the script named "ddg" below in a directory in your
> path, and chmod +x /path/to/ddg ,
> then type at the shell prompt:
>
> $ ddg ENOENT
>
> ----- start of script ddg -----
> #!/usr/bin/perl
> #
> # quickly search duck duck go from command line
> #
> # From: Eli the Bearded <*@eli.users.panix.com>
> # Newsgroups: comp.misc
> # Date: Mon, 12 Apr 2021 17:46:51 +0000 (UTC)
>
> use strict;
> use warnings;
>
> my $browser = 'lynx';
> my @browser_args = qw(
> -useragent=Lynx/2.8.9rel.1
> -image_links
> -noreferer
> -accept_all_cookies
> -cookie_save_file=/dev/null
> );
> my $query = join('+',@ARGV);
> my $base = 'https://duckduckgo.com/lite/';
>
> if(defined($query) and $query ne '') {
> $base .= "?q=$query";
> }
>
> push(@browser_args, $base);
>
> exec($browser, @browser_args);
> ----- end of script ddg -----

Thanks for your perl script. It basically means to open "https://duckduckgo.com/lite/" and search for "ENOENT". But I don't have much understanding of Perl's obscure syntax :-(

Anyway, I found the following explanation from here [1]:

It's an abbreviation of Error NO ENTry (or Error NO ENTity), and can actually be used for more than files/directories.

It's abbreviated because C compilers at the dawn of time didn't support more than 8 characters in symbols.

[1] https://stackoverflow.com/a/19902850

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<sog24n$b1u$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4666&group=comp.unix.shell#4666

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff
on the target place.
Date: Sat, 4 Dec 2021 15:40:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <sog24n$b1u$1@dont-email.me>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 4 Dec 2021 15:40:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6bee4c2280e3ff4404b73bce11677e5b";
logging-data="11326"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183j/RwWSowip88FVHvOF74fG7SlEQlS2E="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:YjpefxFeRxWKzhRUUgGq/jFG5Dw=
 by: Lew Pitcher - Sat, 4 Dec 2021 15:40 UTC

On Fri, 03 Dec 2021 17:33:12 -0800, hongy...@gmail.com wrote:

> werner@X10DAi-00:~$ ls ~/Desktop/
> Downloads.idm.wine "Newton's Principia for The Common
> Reader.djvu"
> File.com.qq.weixin.deepin work FileRecv.com.qq.im.deepin
> 霍金_时间简史.pdf
>
> werner@X10DAi-00:~$ bash -c "cd '$1' && ls " -- ~/Desktop/
Desktop
> Mail PycharmProjects vmware Documents Music
README.md
> Yozo_Officelog.txt Downloads News Templates Zotero
go
> Pictures texmf hs_err_pid2195649.log Public Videos
>
> werner@X10DAi-00:~$ bash -c "cd \$1 && ls " -- ~/Desktop/
> Downloads.idm.wine "Newton's Principia for The Common
Reader.djvu"
> File.com.qq.weixin.deepin work FileRecv.com.qq.im.deepin
> 霍金_时间简史.pdf
>
> werner@X10DAi-00:~$ bash -c 'cd "$1" && ls' -- ~/Desktop/
> Downloads.idm.wine "Newton's Principia for The Common
Reader.djvu"
> File.com.qq.weixin.deepin work FileRecv.com.qq.im.deepin
> 霍金_时间简史.pdf
>
> As you can see, the following two commands works as expected:
>
> $ bash -c "cd \$1 && ls " -- ~/Desktop/
> $ bash -c 'cd "$1" && ls' -- ~/Desktop/
>
> But the following one doesn't:
>
> $ bash -c "cd '$1' && ls " -- ~/Desktop/
>
> Why does bash shell exhibit this behavior?

You have put single-quotes around $1. This will cause
your shell to treat the contents literally, and NOT
expand $1.

HTH
--
Lew Pitcher
"In Skills, We Trust"

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<sohtu3$dc0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4667&group=comp.unix.shell#4667

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Sun, 5 Dec 2021 09:40:35 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <sohtu3$dc0$1@dont-email.me>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<83398d9c-d5ee-4808-ac9e-315763f39702n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 5 Dec 2021 08:40:35 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5257777560a78c51243076bda551ad09";
logging-data="13696"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qk5VojJpRJRXbXQkAZgAe"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:L5RlxS8nHjEZc9Arm0+bIH17V6k=
In-Reply-To: <83398d9c-d5ee-4808-ac9e-315763f39702n@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sun, 5 Dec 2021 08:40 UTC

On 04.12.2021 04:33, hongy...@gmail.com wrote:
>
>> Then what happens if you cd "" to an empty directory string?
>> That seems to depend on the shell. I think it should fail with
>> ENOENT (if I read POSIX correctly).
>
> What do you mean by saying ENOENT?

It was a topical excursion to understand the 'cd' behavior in
the given application context.

By using various forms of quotes/escaped you had got your shell
variable expanded at different stages, effectively resulting in
getting a value or not. In the cases of not getting a value and
using it in context of the 'cd' command the question was how the
'cd' command would behave. Since you had used your command in a
conditional context cd "$arg" && some-cmd it's necessary to
know how cd "" would behave with an empty argument. Kornshell
would report an error ("cd: bad directory") and it seems Bash or
Zsh would not consider it an error but as a no-op. So I inspected
the POSIX specs, and it seemed to me that the given application
case would lead to and be reflected by the 'chdir()' Unix system
call; it should probably be passed back to the shell as an error.
For chdir(2) using an empty string argument the return is defined
as
[ENOENT]
A component of path does not name an existing directory or
path is an empty string.

Since shell's behaviors obviously seems to differ in case of an
empty cd argument the programmer has to take precaution to check
for empty arguments and handle that case appropriately. Or quote
correctly to avoid related bugs.

Janis

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<sohuq4$qld$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4668&group=comp.unix.shell#4668

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Sun, 5 Dec 2021 09:55:31 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <sohuq4$qld$1@dont-email.me>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<83398d9c-d5ee-4808-ac9e-315763f39702n@googlegroups.com>
<sohtu3$dc0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 5 Dec 2021 08:55:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5257777560a78c51243076bda551ad09";
logging-data="27309"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jggmviBRgJBl/u8T+Sf82"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:wVymvLEL3/VSCDTE3yD+8WNM7wY=
In-Reply-To: <sohtu3$dc0$1@dont-email.me>
 by: Janis Papanagnou - Sun, 5 Dec 2021 08:55 UTC

On 05.12.2021 09:40, Janis Papanagnou wrote:
> On 04.12.2021 04:33, hongy...@gmail.com wrote:
>>
>>> Then what happens if you cd "" to an empty directory string?
>>> That seems to depend on the shell. I think it should fail with
>>> ENOENT (if I read POSIX correctly).
>>
>> What do you mean by saying ENOENT?

In my explanations I forgot to mention that it is a standard
error code of Unix system calls. If chdir(2) is used by cd(1)
and chdir(2) produces that error code then cd(1) must handle
it in some (ideally standard-conformant) way. Read text below
with that in mind.

> It was a topical excursion to understand the 'cd' behavior in
> the given application context.
>
> By using various forms of quotes/escaped you had got your shell
> variable expanded at different stages, effectively resulting in
> getting a value or not. In the cases of not getting a value and
> using it in context of the 'cd' command the question was how the
> 'cd' command would behave. Since you had used your command in a
> conditional context cd "$arg" && some-cmd it's necessary to
> know how cd "" would behave with an empty argument. Kornshell
> would report an error ("cd: bad directory") and it seems Bash or
> Zsh would not consider it an error but as a no-op. So I inspected
> the POSIX specs, and it seemed to me that the given application
> case would lead to and be reflected by the 'chdir()' Unix system
> call; it should probably be passed back to the shell as an error.
> For chdir(2) using an empty string argument the return is defined
> as
> [ENOENT]
> A component of path does not name an existing directory or
> path is an empty string.
>
> Since shell's behaviors obviously seems to differ in case of an
> empty cd argument the programmer has to take precaution to check
> for empty arguments and handle that case appropriately. Or quote
> correctly to avoid related bugs.
>
> Janis
>

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4669&group=comp.unix.shell#4669

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:a50:: with SMTP id j16mr30079080qka.766.1638753790430;
Sun, 05 Dec 2021 17:23:10 -0800 (PST)
X-Received: by 2002:a05:6214:1cc5:: with SMTP id g5mr33397155qvd.81.1638753790259;
Sun, 05 Dec 2021 17:23:10 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 5 Dec 2021 17:23:10 -0800 (PST)
In-Reply-To: <soej4h$d76$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.43; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.43
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com> <soej4h$d76$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 06 Dec 2021 01:23:10 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 10
 by: hongy...@gmail.com - Mon, 6 Dec 2021 01:23 UTC

On Saturday, December 4, 2021 at 10:17:58 AM UTC+8, Janis Papanagnou wrote:
> Then what happens if you cd "" to an empty directory string?
> That seems to depend on the shell. I think it should fail with
> ENOENT (if I read POSIX correctly).

See my following testing:

werner@X10DAi-00:~$ cd ""
werner@X10DAi-00:~$

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4670&group=comp.unix.shell#4670

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:27ca:: with SMTP id ge10mr33034282qvb.46.1638754031484;
Sun, 05 Dec 2021 17:27:11 -0800 (PST)
X-Received: by 2002:ac8:5a0b:: with SMTP id n11mr36546092qta.372.1638754031367;
Sun, 05 Dec 2021 17:27:11 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 5 Dec 2021 17:27:11 -0800 (PST)
In-Reply-To: <4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.42; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.42
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me> <4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 06 Dec 2021 01:27:11 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 11
 by: hongy...@gmail.com - Mon, 6 Dec 2021 01:27 UTC

On Monday, December 6, 2021 at 9:23:13 AM UTC+8, hongy...@gmail.com wrote:
> On Saturday, December 4, 2021 at 10:17:58 AM UTC+8, Janis Papanagnou wrote:
> > Then what happens if you cd "" to an empty directory string?
> > That seems to depend on the shell. I think it should fail with
> > ENOENT (if I read POSIX correctly).
> See my following testing:
>
> werner@X10DAi-00:~$ cd ""
> werner@X10DAi-00:~$

werner@X10DAi-00:~$ echo $SHELL
/bin/bash

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<sojq9h$ft1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4671&group=comp.unix.shell#4671

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Mon, 6 Dec 2021 02:50:40 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <sojq9h$ft1$1@dont-email.me>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Dec 2021 01:50:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4f0e88746f80dd8f949bdbeb5c9bd1f6";
logging-data="16289"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197s6WOZLsX6Zs2hfqfOS50"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:1U5EYMOuZijWiXjFTZCbW/cTEo8=
In-Reply-To: <e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Mon, 6 Dec 2021 01:50 UTC

On 06.12.2021 02:27, hongy...@gmail.com wrote:
> On Monday, December 6, 2021 at 9:23:13 AM UTC+8, hongy...@gmail.com wrote:
>> On Saturday, December 4, 2021 at 10:17:58 AM UTC+8, Janis Papanagnou wrote:
>>> Then what happens if you cd "" to an empty directory string?
>>> That seems to depend on the shell. I think it should fail with
>>> ENOENT (if I read POSIX correctly).
>> See my following testing:

Why shall I see it?

>> werner@X10DAi-00:~$ cd ""
>> werner@X10DAi-00:~$
>
> werner@X10DAi-00:~$ echo $SHELL
> /bin/bash

Yes, that's what I said in one of my posts here. Bash reports no error,
despite cd'ing to an non-existing ('ENOENT') directory.

All prominent shells don't change the directory when provided an empty
string. So if you use a conditional like cd "" && cmd Bash and Zsh
will execute the cmd despite the cd had no effect. In your case of a
cd "$undef_var" that might not be a very helpful behavior, but it's on
you to fix it by taking some measure that undef_var will get _defined_.

Janis

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<op.1dykrhjaa3w0dxdave@hodgins.homeip.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4672&group=comp.unix.shell#4672

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dwhodg...@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Sun, 05 Dec 2021 21:48:43 -0500
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="3c30d356a1ca4acc58f5bdfbf3e4dce5";
logging-data="4337"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fko+xb1uiR3eg5FdFwIurr8K20Ep3wrM="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:48Wlf9jwhpglkCkgNtRSvrJveUE=
 by: David W. Hodgins - Mon, 6 Dec 2021 02:48 UTC

On Sun, 05 Dec 2021 20:50:40 -0500, Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:

> On 06.12.2021 02:27, hongy...@gmail.com wrote:
>> On Monday, December 6, 2021 at 9:23:13 AM UTC+8, hongy...@gmail.com wrote:
>>> On Saturday, December 4, 2021 at 10:17:58 AM UTC+8, Janis Papanagnou wrote:
>>>> Then what happens if you cd "" to an empty directory string?
>>>> That seems to depend on the shell. I think it should fail with
>>>> ENOENT (if I read POSIX correctly).
>>> See my following testing:
>
> Why shall I see it?
>
>>> werner@X10DAi-00:~$ cd ""
>>> werner@X10DAi-00:~$
>>
>> werner@X10DAi-00:~$ echo $SHELL
>> /bin/bash
>
> Yes, that's what I said in one of my posts here. Bash reports no error,
> despite cd'ing to an non-existing ('ENOENT') directory.

From "man bash"
cd [-L|[-P [-e]] [-@]] [dir]
Change the current directory to dir. if dir is not supplied, the value of the HOME shell variable is the default.

[dave@x3 Documents]$ pwd
/home/dave/Documents
[dave@x3 Documents]$ cd
[dave@x3 ~]$ pwd
/home/dave

[dave@x3 ~]$ grep dave /etc/passwd
dave:x:500:500:David W. Hodgins:/home/dave:/bin/bash

[dave@x3 ~]$ bash --version|head -n 1
GNU bash, version 5.1.4(1)-release (x86_64-mageia-linux-gnu)

Regards, Dave Hodgins

Regards, Dave Hodgins

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4673&group=comp.unix.shell#4673

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a37:2784:: with SMTP id n126mr31096956qkn.691.1638759700607;
Sun, 05 Dec 2021 19:01:40 -0800 (PST)
X-Received: by 2002:ac8:45d2:: with SMTP id e18mr36604953qto.112.1638759700449;
Sun, 05 Dec 2021 19:01:40 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 5 Dec 2021 19:01:40 -0800 (PST)
In-Reply-To: <op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
Injection-Info: google-groups.googlegroups.com; posting-host=172.104.65.59; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 172.104.65.59
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me> <4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com> <sojq9h$ft1$1@dont-email.me>
<op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
From: hongyi.z...@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 06 Dec 2021 03:01:40 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 35
 by: hongy...@gmail.com - Mon, 6 Dec 2021 03:01 UTC

On Monday, December 6, 2021 at 10:48:57 AM UTC+8, David W. Hodgins wrote:
> On Sun, 05 Dec 2021 20:50:40 -0500, Janis Papanagnou <janis_pa...@hotmail.com> wrote:
>
> > On 06.12.2021 02:27, hongy...@gmail.com wrote:
> >> On Monday, December 6, 2021 at 9:23:13 AM UTC+8, hongy...@gmail.com wrote:
> >>> On Saturday, December 4, 2021 at 10:17:58 AM UTC+8, Janis Papanagnou wrote:
> >>>> Then what happens if you cd "" to an empty directory string?
> >>>> That seems to depend on the shell. I think it should fail with
> >>>> ENOENT (if I read POSIX correctly).
> >>> See my following testing:
> >
> > Why shall I see it?
> >
> >>> werner@X10DAi-00:~$ cd ""
> >>> werner@X10DAi-00:~$
> >>
> >> werner@X10DAi-00:~$ echo $SHELL
> >> /bin/bash
> >
> > Yes, that's what I said in one of my posts here. Bash reports no error,
> > despite cd'ing to an non-existing ('ENOENT') directory.
> From "man bash"
> cd [-L|[-P [-e]] [-@]] [dir]
> Change the current directory to dir. if dir is not supplied, the value of the HOME shell variable is the default.

But if an empty string is supplied, NO-OP is the observed behavior for bash shell:

werner@X10DAi-00:~/Desktop$ pwd
/home/werner/Desktop
werner@X10DAi-00:~/Desktop$ cd ''
werner@X10DAi-00:~/Desktop$ pwd
/home/werner/Desktop
werner@X10DAi-00:~/Desktop$ cd ""
werner@X10DAi-00:~/Desktop$ pwd
/home/werner/Desktop

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<op.1dynetd6a3w0dxdave@hodgins.homeip.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4674&group=comp.unix.shell#4674

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dwhodg...@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Sun, 05 Dec 2021 22:45:55 -0500
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <op.1dynetd6a3w0dxdave@hodgins.homeip.net>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me> <op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
<bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="3c30d356a1ca4acc58f5bdfbf3e4dce5";
logging-data="20460"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gMsZ9YxGXJcDLMZ3oFxBfuycWRYd6DN4="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:DEBDs4HP0Iw63JdYdqlRmq2Nuxg=
 by: David W. Hodgins - Mon, 6 Dec 2021 03:45 UTC

On Sun, 05 Dec 2021 22:01:40 -0500, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:

> On Monday, December 6, 2021 at 10:48:57 AM UTC+8, David W. Hodgins wrote:
>> On Sun, 05 Dec 2021 20:50:40 -0500, Janis Papanagnou <janis_pa...@hotmail.com> wrote:
>>
>> > On 06.12.2021 02:27, hongy...@gmail.com wrote:
>> >> On Monday, December 6, 2021 at 9:23:13 AM UTC+8, hongy...@gmail.com wrote:
>> >>> On Saturday, December 4, 2021 at 10:17:58 AM UTC+8, Janis Papanagnou wrote:
>> >>>> Then what happens if you cd "" to an empty directory string?
>> >>>> That seems to depend on the shell. I think it should fail with
>> >>>> ENOENT (if I read POSIX correctly).
>> >>> See my following testing:
>> >
>> > Why shall I see it?
>> >
>> >>> werner@X10DAi-00:~$ cd ""
>> >>> werner@X10DAi-00:~$
>> >>
>> >> werner@X10DAi-00:~$ echo $SHELL
>> >> /bin/bash
>> >
>> > Yes, that's what I said in one of my posts here. Bash reports no error,
>> > despite cd'ing to an non-existing ('ENOENT') directory.
>> From "man bash"
>> cd [-L|[-P [-e]] [-@]] [dir]
>> Change the current directory to dir. if dir is not supplied, the value of the HOME shell variable is the default.
>
> But if an empty string is supplied, NO-OP is the observed behavior for bash shell:
>
> werner@X10DAi-00:~/Desktop$ pwd
> /home/werner/Desktop
> werner@X10DAi-00:~/Desktop$ cd ''
> werner@X10DAi-00:~/Desktop$ pwd
> /home/werner/Desktop
> werner@X10DAi-00:~/Desktop$ cd ""
> werner@X10DAi-00:~/Desktop$ pwd
> /home/werner/Desktop

Ah. Correct. A null variable is not the same as no variable and causes the cd
command to become a nop.

I agree that should be treated as an error rather then a nop.

Regards, Dave Hodgins

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<cf2e2582-de95-483e-a790-62e2af4a5629n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4675&group=comp.unix.shell#4675

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:6214:1d03:: with SMTP id e3mr34830691qvd.61.1638768628190;
Sun, 05 Dec 2021 21:30:28 -0800 (PST)
X-Received: by 2002:a37:a44f:: with SMTP id n76mr31318709qke.734.1638768627931;
Sun, 05 Dec 2021 21:30:27 -0800 (PST)
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 5 Dec 2021 21:30:27 -0800 (PST)
In-Reply-To: <op.1dynetd6a3w0dxdave@hodgins.homeip.net>
Injection-Info: google-groups.googlegroups.com; posting-host=78.173.140.236; posting-account=RbOzpwoAAACSDI6OO1wVarfPakNstxUl
NNTP-Posting-Host: 78.173.140.236
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me> <4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com> <sojq9h$ft1$1@dont-email.me>
<op.1dykrhjaa3w0dxdave@hodgins.homeip.net> <bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
<op.1dynetd6a3w0dxdave@hodgins.homeip.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cf2e2582-de95-483e-a790-62e2af4a5629n@googlegroups.com>
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
From: oguzisma...@gmail.com (Oğuz)
Injection-Date: Mon, 06 Dec 2021 05:30:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 126
 by: Oğuz - Mon, 6 Dec 2021 05:30 UTC

On Monday, December 6, 2021 at 6:46:04 AM UTC+3, David W. Hodgins wrote:
> Ah. Correct. A null variable is not the same as no variable and causes the cd
> command to become a nop.

Not really. See:

$ for sh in bash 'bash -o posix' bash-3.2.57 'bash-3.2.57 -o posix' bosh 'bosh -o posix' 'busybox sh' dash gwsh heirloom-sh ksh 'ksh -o posix' mksh 'mksh -o posix' 'mksh -o sh' oksh 'oksh -o posix' 'oksh -o sh' pdksh 'pdksh -o posix' posh yash 'yash -o posixly-correct' zsh 'zsh --emulate sh' 'zsh --emulate ksh'; do
> echo $sh
> $sh -c 'pwd; CDPATH=/ cd ""'
> echo
> done
bash
/home/oguz
/

bash -o posix
/home/oguz
/

bash-3.2.57
/home/oguz
/

bash-3.2.57 -o posix
/home/oguz
/

bosh
/home/oguz
bosh: null directory

bosh -o posix
/home/oguz
bosh: null directory

busybox sh
/home/oguz
//

dash
/home/oguz
//

gwsh
/home/oguz
gwsh: 1: cd: : No such file or directory

heirloom-sh
/home/oguz
heirloom-sh: null directory

ksh
/home/oguz
ksh: cd: bad directory

ksh -o posix
/home/oguz
ksh: cd: bad directory

mksh
/home/oguz
/

mksh -o posix
/home/oguz
/

mksh -o sh
/home/oguz
/

oksh
/home/oguz
/

oksh -o posix
/home/oguz
/

oksh -o sh
/home/oguz
/

pdksh
/home/oguz
/

pdksh -o posix
/home/oguz
/

posh
/home/oguz
/

yash
/home/oguz

yash -o posixly-correct
/home/oguz

zsh
/home/oguz

zsh --emulate sh
/home/oguz
/

zsh --emulate ksh
/home/oguz
/

$

>
> I agree that should be treated as an error rather then a nop.

I disagree; an empty string is a valid relative pathname. Shells above that error out/change pwd to `//' are broken.

>
> Regards, Dave Hodgins

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<sokck0$7bm$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4676&group=comp.unix.shell#4676

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Mon, 6 Dec 2021 08:03:28 +0100
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <sokck0$7bm$1@dont-email.me>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me> <op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
<bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
<op.1dynetd6a3w0dxdave@hodgins.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Dec 2021 07:03:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4f0e88746f80dd8f949bdbeb5c9bd1f6";
logging-data="7542"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QCTirrEZRf5E/0sBeKCcI"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:gkfVTJxpm89nhnbXduq93iLDHzE=
In-Reply-To: <op.1dynetd6a3w0dxdave@hodgins.homeip.net>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Mon, 6 Dec 2021 07:03 UTC

On 06.12.2021 04:45, David W. Hodgins wrote:
>
> Ah. Correct. A null variable is not the same as no variable and causes
> the cd
> command to become a nop.
>
> I agree that should be treated as an error rather then a nop.

Well, the POSIX standard - after a very long procedural description
of what has to be done with directories in absolute or relative form,
given options -L and -P, given . and .., or with CDPATH specified or
not, and whatnot else - just specifies

"If directory is an empty string, the results are unspecified."

So I'd say that whatever outcome cd has given an empty string - whether
it appears to be sensible or inappropriate - is allowed by POSIX. (For
errors they say: "The working directory shall remain unchanged.")

Since files and directories have non-null names, specifying an empty
value I'd consider a programming-error that should be resulting in
an error that can be detected, caught and handled. (And, luckily, the
shell I practically prefer for many reasons does exactly that.)

The key (still) seems to be to specify a _non-empty_ directory argument
(by a correctly expanded and correctly quoted variable, if an argument
is provided that way).

Janis

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<sol9fu$cn6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4677&group=comp.unix.shell#4677

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chr...@mshome.net (Chris Elvidge)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Mon, 6 Dec 2021 15:15:58 +0000
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <sol9fu$cn6$1@dont-email.me>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me> <op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
<bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
<op.1dynetd6a3w0dxdave@hodgins.homeip.net> <sokck0$7bm$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Dec 2021 15:16:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="08fa45d0fb35b738a435cb2e191476a9";
logging-data="13030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dWiF98A13Cz8mZ8cmL8MMdaVw3GmrOsQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
Thunderbird/52.2.1 Lightning/5.4
Cancel-Lock: sha1:1QXnvRVT5+3JLN+kDXVXl4IVCMg=
In-Reply-To: <sokck0$7bm$1@dont-email.me>
Content-Language: en-GB
 by: Chris Elvidge - Mon, 6 Dec 2021 15:15 UTC

On 06/12/2021 07:03 am, Janis Papanagnou wrote:
> On 06.12.2021 04:45, David W. Hodgins wrote:
>>
>> Ah. Correct. A null variable is not the same as no variable and causes
>> the cd
>> command to become a nop.
>>
>> I agree that should be treated as an error rather then a nop.
>
> Well, the POSIX standard - after a very long procedural description
> of what has to be done with directories in absolute or relative form,
> given options -L and -P, given . and .., or with CDPATH specified or
> not, and whatnot else - just specifies
>
> "If directory is an empty string, the results are unspecified."
>
> So I'd say that whatever outcome cd has given an empty string - whether
> it appears to be sensible or inappropriate - is allowed by POSIX. (For
> errors they say: "The working directory shall remain unchanged.")
>
> Since files and directories have non-null names, specifying an empty
> value I'd consider a programming-error that should be resulting in
> an error that can be detected, caught and handled. (And, luckily, the
> shell I practically prefer for many reasons does exactly that.)
>
> The key (still) seems to be to specify a _non-empty_ directory argument
> (by a correctly expanded and correctly quoted variable, if an argument
> is provided that way).
>
> Janis
>

In bash, it also seems to depend on whether CDPATH is set or not.
With CDPATH unset, both cd "" and cd '' do not change the current
working directory (bash 5.1.12).
With CDPATH set, it seems to change to the first item in CDPATH.
(One reason I do not export CDPATH.)

(ksh gives an error, as you say.)

--
Chris Elvidge
England

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<874k7ld12o.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4678&group=comp.unix.shell#4678

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.
Date: Mon, 06 Dec 2021 10:45:35 -0800
Organization: None to speak of
Lines: 15
Message-ID: <874k7ld12o.fsf@nosuchdomain.example.com>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="8a44e9d9a9b2a2115bfb2aee4d38e675";
logging-data="11148"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2h7h/CwE2bsbNKE86PW0h"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Yi+umCU6cb4vgiTNTjCj3ocvdjo=
sha1:/2jCm9FwoAquMoTKa/eF7ANBdtQ=
 by: Keith Thompson - Mon, 6 Dec 2021 18:45 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com> writes:
[...]
> All prominent shells don't change the directory when provided an empty
> string. So if you use a conditional like cd "" && cmd Bash and Zsh
> will execute the cmd despite the cd had no effect. In your case of a
> cd "$undef_var" that might not be a very helpful behavior, but it's on
> you to fix it by taking some measure that undef_var will get _defined_.

csh, tcsh, and fish all report an error on "cd ''". (Not arguing
whether any of them are "prominent").

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<87zgpdbjul.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4679&group=comp.unix.shell#4679

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.
Date: Mon, 06 Dec 2021 11:42:58 -0800
Organization: None to speak of
Lines: 16
Message-ID: <87zgpdbjul.fsf@nosuchdomain.example.com>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me>
<op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
<bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
<op.1dynetd6a3w0dxdave@hodgins.homeip.net>
<cf2e2582-de95-483e-a790-62e2af4a5629n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="8a44e9d9a9b2a2115bfb2aee4d38e675";
logging-data="32660"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Go7l6JhAQeLkhG3YvjYv9"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:lJkVGn4xSVq5M0SNxeo1yR7rFBU=
sha1:XMK31+EG9tQE/B1nRs8TV+Qyy7g=
 by: Keith Thompson - Mon, 6 Dec 2021 19:42 UTC

Oğuz <oguzismailuysal@gmail.com> writes:
[...]
> I disagree; an empty string is a valid relative pathname. Shells above
> that error out/change pwd to `//' are broken.

An interesting idea, but not one that's supported by POSIX.

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
Pathname Resolution:

A null pathname shall not be successfully resolved.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<somj96$s6a$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4681&group=comp.unix.shell#4681

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
Date: Tue, 7 Dec 2021 04:09:25 +0100
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <somj96$s6a$1@dont-email.me>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me> <874k7ld12o.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 7 Dec 2021 03:09:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="dbf2d7ee74472c26bdfc0af2664574bf";
logging-data="28874"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+n6+8YVNEZyx3s6867zA/o"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:T3NAbHRfqFwiQNW0H/3JZdsftY4=
In-Reply-To: <874k7ld12o.fsf@nosuchdomain.example.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 7 Dec 2021 03:09 UTC

On 06.12.2021 19:45, Keith Thompson wrote:
> Janis Papanagnou <janis_papanagnou@hotmail.com> writes:
> [...]
>> All prominent shells don't change the directory when provided an empty
>> string. So if you use a conditional like cd "" && cmd Bash and Zsh
>> will execute the cmd despite the cd had no effect. In your case of a
>> cd "$undef_var" that might not be a very helpful behavior, but it's on
>> you to fix it by taking some measure that undef_var will get _defined_.
>
> csh, tcsh, and fish all report an error on "cd ''". (Not arguing
> whether any of them are "prominent").

I used that word to sum up ksh, bash, and zsh, the powerful standard
shells typically used for programming, and in distinction to the
minimum feature shells like pure POSIX or Bourne shell, and also in
distinction to shells not (sensibly) suitable for programming like
the mentioned csh-based ones. That's the primary reason for using
the word "prominent", to specify a specific set (or class) of shells
that are suitable for comfortable programming and that have a POSIX
standard conforming base. (And I haven't found a better word for it.)

Janis

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<7bc95561-2bcc-4553-96be-e6a475b4567en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4682&group=comp.unix.shell#4682

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:199a:: with SMTP id bm26mr38987456qkb.542.1638853640484;
Mon, 06 Dec 2021 21:07:20 -0800 (PST)
X-Received: by 2002:a05:622a:1392:: with SMTP id o18mr45378352qtk.270.1638853640263;
Mon, 06 Dec 2021 21:07:20 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Mon, 6 Dec 2021 21:07:20 -0800 (PST)
In-Reply-To: <87zgpdbjul.fsf@nosuchdomain.example.com>
Injection-Info: google-groups.googlegroups.com; posting-host=95.5.130.196; posting-account=RbOzpwoAAACSDI6OO1wVarfPakNstxUl
NNTP-Posting-Host: 95.5.130.196
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me> <4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com> <sojq9h$ft1$1@dont-email.me>
<op.1dykrhjaa3w0dxdave@hodgins.homeip.net> <bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
<op.1dynetd6a3w0dxdave@hodgins.homeip.net> <cf2e2582-de95-483e-a790-62e2af4a5629n@googlegroups.com>
<87zgpdbjul.fsf@nosuchdomain.example.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7bc95561-2bcc-4553-96be-e6a475b4567en@googlegroups.com>
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on
the target place.
From: oguzisma...@gmail.com (Oğuz)
Injection-Date: Tue, 07 Dec 2021 05:07:20 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2136
 by: Oğuz - Tue, 7 Dec 2021 05:07 UTC

On Monday, December 6, 2021 at 10:44:30 PM UTC+3, Keith Thompson wrote:
> An interesting idea, but not one that's supported by POSIX.

I know,

>
> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
> Pathname Resolution:
>
> A null pathname shall not be successfully resolved.

but why? As a security measure?

> --
> Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
> Working, but not speaking, for Philips
> void Void(void) { Void(); } /* The recursive call of the void */

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<83mtlcb0z5.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4685&group=comp.unix.shell#4685

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!5W3hg5pwOjWZBw6yj59qJg.user.46.165.242.75.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.
Date: Tue, 07 Dec 2021 21:42:54 +0100
Organization: Aioe.org NNTP Server
Message-ID: <83mtlcb0z5.fsf@helmutwaitzmann.news.arcor.de>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me>
<op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
<bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
<op.1dynetd6a3w0dxdave@hodgins.homeip.net>
<cf2e2582-de95-483e-a790-62e2af4a5629n@googlegroups.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="25147"; posting-host="5W3hg5pwOjWZBw6yj59qJg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Mail-Copies-To: nobody
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:a/FIDLxEkel/ejAot/+bU98G7mw=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
 by: Helmut Waitzmann - Tue, 7 Dec 2021 20:42 UTC

Oğuz <oguzismailuysal@gmail.com>:

>I disagree; an empty string is a valid relative pathname. Shells
>above that error out/change pwd to `//' are broken.
>

Do you agree with the following statement?

If (read as shell command line syntax)

"${somedir}"

denotes a relative pathname that resolves to a directory, then if

"${somedir%/}"/subdir

resolves to a directory and does not resolve to a symbolic link to a
directory, then that directory should be a subdirectory of

"${somedir}"

and

"${somedir%/}"/subdir/..

should resolve to the same directory as

"${somedir}"

does.

Three examples:

First, define a shell function:

create_and_show_subdir_of()
(
# Do not exit on error:
set +e

set -- "${1?}" "${1%/}"/subdir "${1%/}"/subdir/.. &&

# "${1%/}" gives the value of the positional parameter
# no. 1 with a trailing slash (in case it's there)
# removed.

mkdir -- "$2" &&
{
if test "$1" -ef "$3"
then
format='%s\nand\n%s\nare the same.\n'
else
format='%s\nand\n%s\nare not the same.\n'
fi
ls -ldi -- "$@"
printf "$format" "$1" "$3"
rmdir -- "$2"
}
)

Then call that function using different parameters:

create_and_show_subdir_of 'a/relative/pathname'

create_and_show_subdir_of '.'

Now, try that function with the null pathname:

create_and_show_subdir_of ''

Do you see the inconsistency?

If "" (the empty pathname) ever should be a valid pathname, I would
vote for it to be the root directory, not the current working
directory.

See also the posting

Subject: Re: Why is "" (empty) not a valid file name?
From: Helmut Waitzmann <nn.throttle@xoxy.net>
Newsgroups: comp.unix.shell
Date: Sat, 25 Apr 2020 01:30:18 +0200
Message-ID: <83r1wcfomt.fsf@helmutwaitzmann.news.arcor.de>
References: <hgav4gF8lhuU1@mid.individual.net>
<83v9lqgiiv.fsf@helmutwaitzmann.news.arcor.de>
<hge7tuFu3k2U1@mid.individual.net>
<83sggugcrm.fsf@helmutwaitzmann.news.arcor.de>
<hgg69gFauu4U1@mid.individual.net>

and its ancestor postings (Google might have archived them.  If not,
I can provide the contents of the posting.).

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<87ee6oazda.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4686&group=comp.unix.shell#4686

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.
Date: Tue, 07 Dec 2021 13:17:37 -0800
Organization: None to speak of
Lines: 15
Message-ID: <87ee6oazda.fsf@nosuchdomain.example.com>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me>
<op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
<bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
<op.1dynetd6a3w0dxdave@hodgins.homeip.net>
<cf2e2582-de95-483e-a790-62e2af4a5629n@googlegroups.com>
<83mtlcb0z5.fsf@helmutwaitzmann.news.arcor.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="7f90512ec77176d2b122f800cb8bb3bb";
logging-data="16533"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Fj354ZLtLBAvWiM5Gghd/"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:s+Yx0H3pt9CuwgPrB+bcuWNVaz8=
sha1:AhNDCksW5hxp0jW84AwjS5j33PY=
 by: Keith Thompson - Tue, 7 Dec 2021 21:17 UTC

Helmut Waitzmann <nn.throttle@xoxy.net> writes:
[...]
> If "" (the empty pathname) ever should be a valid pathname, I would
> vote for it to be the root directory, not the current working
> directory.
[...]

But then it would be in effect an absolute pathname even though it
doesn't start with a '/' character. I can see that causing more
problems.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.

<831r2nbbwr.fsf@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=4692&group=comp.unix.shell#4692

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!i2pn.org!aioe.org!H6XxZVAOJuj/8a8bYFaPlQ.user.46.165.242.75.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: bash -c "cd '$1' && ls" -- ~/Desktop/ can't display the stuff on the target place.
Date: Wed, 08 Dec 2021 11:59:00 +0100
Organization: Aioe.org NNTP Server
Message-ID: <831r2nbbwr.fsf@helmutwaitzmann.news.arcor.de>
References: <ae90a3a6-e976-42ca-a325-b88bd88fe13bn@googlegroups.com>
<soej4h$d76$1@dont-email.me>
<4e31baeb-a54c-443b-b33c-5d5cb9a3de21n@googlegroups.com>
<e0025de7-3cff-4b86-aff2-3da19b180270n@googlegroups.com>
<sojq9h$ft1$1@dont-email.me>
<op.1dykrhjaa3w0dxdave@hodgins.homeip.net>
<bafc486b-3bef-4fd3-8a4d-88289fe86728n@googlegroups.com>
<op.1dynetd6a3w0dxdave@hodgins.homeip.net>
<cf2e2582-de95-483e-a790-62e2af4a5629n@googlegroups.com>
<83mtlcb0z5.fsf@helmutwaitzmann.news.arcor.de>
<87ee6oazda.fsf@nosuchdomain.example.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="22086"; posting-host="H6XxZVAOJuj/8a8bYFaPlQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
X-Notice: Filtered by postfilter v. 0.9.2
Mail-Copies-To: nobody
Cancel-Lock: sha1:6Z/dhNhB2vYzyGgGZXYCOJGPpF8=
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
 by: Helmut Waitzmann - Wed, 8 Dec 2021 10:59 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com>:
>Helmut Waitzmann <nn.throttle@xoxy.net> writes:
>[...]
>> If "" (the empty pathname) ever should be a valid pathname, I would
>> vote for it to be the root directory, not the current working
>> directory.
>[...]
>
>But then it would be in effect an absolute pathname even though it
>doesn't start with a '/' character.

Yes, but if viewed from a different direction that is not a problem:

The common rule to decide whether a pathname is an absolute or a
relative one is as follows:

If the first character of a pathname is a slash, the pathname is an
absolute one, else a relative one.

But one could imagine a different rule:

If the first character of a pathname is a character other than a
slash, the pathname is a relative one, else an absolute one.

If the following rule is added to restrict each of the two rules
above, then the two rule sets are equivalent:  If the pathname is
the empty path, then it is an invalid pathname.

I think, the fact that absolute pathnames start with a slash, is
only by coincidence.  The real cause of this coincidence can be
imagined as follows:

The (hidden) leading pathname component of the root directory is the
empty component.  The empty pathname is set to be an invalid
pathname.

The consequence of this is, that the root directory cannot be named
without a trailing slash.

Every pathname denoting a directory can be named with a trailing
slash, and that trailing slash does not hurt in any way.

The only difference where a trailing slash after a non‐empty
pathname makes a difference, is the case, where that pathname
denotes a symbolic link that refers to a directory.

But as the root directory will never be a symbolic link, forbidding
the empty pathname will cause no harm.

=> Absolute pathnames, i. e. pathnames starting with the root
directory, always begin with an empty pathname component followed by
a slash, which is textually the same as beginning with a slash.

>I can see that causing more problems.
>

Maybe that's the reason why the empty pathname has been defined to
be an invalid pathname.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor