[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] avoiding shell variable expansion
From: |
Andy Chu |
Subject: |
Re: [Help-bash] avoiding shell variable expansion |
Date: |
Thu, 3 Oct 2019 15:30:14 -0700 |
Simplest way:
1. Store the command in an array. Quote each arg properly.
mycmd=(ls '*')
2. Then run
$ "${mycmd[@]}"
ls: cannot access '*': No such file or directory
You probably want to memorize / copy-paste that sequence of characters.
See my blog post:
Thirteen Incorrect Ways and Two Awkward Ways to Use Arrays
https://www.oilshell.org/blog/2016/11/06.html
Andy
On Thu, Oct 3, 2019 at 3:07 PM Greg Silverman <address@hidden>
wrote:
> In Python one can spawn a child process and avoid bash expanding command
> line arguments, e.g.
>
> //file: ls.py
> import subprocess
> proc = subprocess.Popen(['/bin/ls','*'],shell=False)
>
> then
> ./ls.py
> /bin/ls: cannot access '*': No such file or directory
>
> As the shell argument is set to False, the ls command is not passed to
> bash before being executed and the star is not expanded to ${PWD}.
>
> Is there a way to launch a command from a bash script which, also, avoids
> shell expansion? This question is for security, to avoid code injection.
>
> Thanks,
>
> Greg Silverman
> Principal Engineer
> Veritas Technologies
> Santa Clara, CA
>
>
- [Help-bash] avoiding shell variable expansion, Greg Silverman, 2019/10/03
- Re: [Help-bash] avoiding shell variable expansion,
Andy Chu <=
- Re: [Help-bash] avoiding shell variable expansion, Dmitry Alexandrov, 2019/10/03
- Re: [Help-bash] avoiding shell variable expansion, Eli Schwartz, 2019/10/04
- Re: [Help-bash] avoiding shell variable expansion, Andy Chu, 2019/10/04
- Re: [Help-bash] avoiding shell variable expansion, Andy Chu, 2019/10/04
- Re: [Help-bash] avoiding shell variable expansion, Dmitry Alexandrov, 2019/10/04
- Re: [Help-bash] avoiding shell variable expansion, Andy Chu, 2019/10/04
- Re: [Help-bash] avoiding shell variable expansion, Eli Schwartz, 2019/10/04
Re: [Help-bash] avoiding shell variable expansion, Eli Schwartz, 2019/10/04
Re: [Help-bash] avoiding shell variable expansion, Andreas Kusalananda Kähäri, 2019/10/04
Re: [Help-bash] avoiding shell variable expansion, Stephane Chazelas, 2019/10/04