Most people who have had some experience with Golang have probably had struggled with its dependency management system. Starting with vendor, managed by community driven tools with varied features and user experiences, to the short-lived, Google-branded dep tool, now the module mechanism with official tooling that controls not only dependencies but their find-grained versions.
Some of the official command tools changed their behavior along the way. go get was once used to download and install packages onto the local system. It's now repurposed to resolve dependencies of the current module (modifying go.mod file) and install them, in the current, module-aware realm. What if you simply need the old behavior, i.e. installing a package without messing with your current Golang code? You have the following two options.
1. If this package you're trying to install has absolutely nothing to do with your current project, you can disable the module aware mode temporarily.
2. If this package is not a direct dependency of your project, but relates to your code in some way, e.g. a CI tool like goimports that checks your code, you might as well record its version in your project, so that you don't end up saying "it works in my environment" some day.
2020年7月14日星期二
2020年7月11日星期六
Bash process substitution, named pipe, or < <()
If you at some point run into a bash code block, while maybe, and at its end you see something like
< <(some_command)
You might then ask, what the heck is this and what does it do?
The <(some_command) part is called process substitution. In a nutshell it serves as a file name, whose content is substituted by the execution output of some_command. The first < then feeds the content to the code block as stdin, the standard IO redirection as you are already familiar with.
Can I just do some_command | while ... which seems more straightforward? Well, sometimes you can. But you should know that in this way the while part is executed in a sub shell and whatever variable you modify there won't be persisted in the current shell.
Under the hood process substitution is implemented by named pipes or /dev/fd.
References:
- https://www.linuxjournal.com/content/shell-process-redirection
- https://www.linuxjournal.com/article/2156
< <(some_command)
You might then ask, what the heck is this and what does it do?
The <(some_command) part is called process substitution. In a nutshell it serves as a file name, whose content is substituted by the execution output of some_command. The first < then feeds the content to the code block as stdin, the standard IO redirection as you are already familiar with.
Can I just do some_command | while ... which seems more straightforward? Well, sometimes you can. But you should know that in this way the while part is executed in a sub shell and whatever variable you modify there won't be persisted in the current shell.
Under the hood process substitution is implemented by named pipes or /dev/fd.
References:
- https://www.linuxjournal.com/content/shell-process-redirection
- https://www.linuxjournal.com/article/2156
订阅:
评论 (Atom)