binpash / try

Inspect a command's effects before modifying your live system
MIT License
5.17k stars 64 forks source link

bug: environment differs inside try #153

Open ezrizhu opened 3 months ago

ezrizhu commented 3 months ago

a

mgree commented 1 month ago

Which side is the real env and which side is inside try?

Fixing $PWD and $OLDPWD is easy. Fixing $_ is trickier:

 : mgreenbe@hippogriff:~/try [configure-install] ; echo $_
bash
: mgreenbe@hippogriff:~/try [configure-install] ; _=flash
: mgreenbe@hippogriff:~/try [configure-install] ; echo $_

: mgreenbe@hippogriff:~/try [configure-install] ; _=flash bash -c 'echo hi $_'
hi /usr/bin/bash

Bash won't let you set $_, even in a local-assignment We might be able to trick it using env, as in /usr/bin/env _="$_" ...:

: mgreenbe@hippogriff:~/try [configure-install] ; env _=flash bash -c 'echo hi $_'
hi flash