[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sr #111125] compgen does not complete paths starting with environment v
From: |
anonymous |
Subject: |
[sr #111125] compgen does not complete paths starting with environment variables when called indirectly |
Date: |
Wed, 25 Sep 2024 03:19:04 -0400 (EDT) |
URL:
<https://savannah.gnu.org/support/?111125>
Summary: compgen does not complete paths starting with
environment variables when called indirectly
Group: The GNU Bourne-Again SHell
Submitter: None
Submitted: Wed 25 Sep 2024 07:18:59 AM UTC
Category: None
Priority: 5 - Normal
Severity: 3 - Normal
Status: None
Privacy: Public
Assigned to: None
Originator Email: florian.pommerening@unibas.ch
Open/Closed: Open
Discussion Lock: Any
Operating System: GNU/Linux
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Wed 25 Sep 2024 07:18:59 AM UTC By: Anonymous
[I also posted this on Stackoverflow but this might be the better place for
it. Original post: https://stackoverflow.com/questions/78978949]
With compgen I can complete paths inside a directory and this can include
environment variables if they are not resolved before calling compgen.
> cd /tmp
> mkdir files
> touch files/aa files/ab
> export MY_FILES=/tmp/files
> echo "$MY_FILES/"
/tmp/files
> compgen -v -A file -- "$MY_FILES/" # not what I want
/tmp/files/ab
/tmp/files/aa
> echo "\$MY_FILES/"
$MY_FILES/
> compgen -v -A file -- "\$MY_FILES/" # this is what I want
$MY_FILES/ab
$MY_FILES/aa
This works fine when I execute the command but doesn't work when the command
is called indirectly (not even in a login shell)
> bash -ilc 'echo "\$MY_FILES/"; compgen -v -A file -- "\$MY_FILES/"'
$MY_FILES/
> echo $?
1
You can tell from the echo command that the escaping works as intended, so
this is not an issue with how the string is escaped.
Likewise, putting the line in a script and calling the script doesn't work:
> cat run-compgen
#!/bin/bash -il
echo "\$MY_FILES/"
compgen -v -A file -- "\$MY_FILES/"
echo $?
> ./run-compgen
$MY_FILES/
1
I also tried calling env indirectly to ensure that the variable is defined in
the nested shell and I tried the above example in a clean ubuntu docker
container to exclude any influence of my setup. Any idea how to get this to
work?
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/support/?111125>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
Description: PGP signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [sr #111125] compgen does not complete paths starting with environment variables when called indirectly,
anonymous <=