mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-24 02:20:09 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
56001f5002
@ -0,0 +1,68 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (5 tips for making documentation a priority in open source projects)
|
||||
[#]: via: (https://opensource.com/article/20/8/documentation-open-source-projects)
|
||||
[#]: author: (Ray Paik https://opensource.com/users/rpaik)
|
||||
|
||||
5 tips for making documentation a priority in open source projects
|
||||
======
|
||||
Documentation is as important as code, so make sure you treat it that
|
||||
way. Here's how.
|
||||
![Files in a folder][1]
|
||||
|
||||
[Open source software][2] is now mainstream; long gone are the days when open source projects attracted developers alone. Nowadays, users across numerous industries are active consumers of open source software, and you can't expect everyone to know how to use the software just by reading the code.
|
||||
|
||||
Even for developers (including those with plenty of experience in other open source projects), good documentation serves as a valuable onboarding tool when people join a community. People who are interested in contributing to a project often start by working on documentation to get familiar with the project, the community, and the community workflow.
|
||||
|
||||
### Common challenges with documentation in open source
|
||||
|
||||
Although everyone agrees that documentation is important and needs to be done, some of the ways we do it result in poor quality and lack of consistency across different parts of documentation in the project. For example, when developers are too focused on code, they don't start working on documentation until the last minute (e.g., right before the release). And all too often, documentation tasks are done by volunteers, people who have a hard time saying "no." To make things worse, people may forget about the documentation after the release, so they never change or improve it, and the vicious cycle repeats.
|
||||
|
||||
### 5 best practices
|
||||
|
||||
We have been involved in documentation in a number of open source projects at [Linux Foundation Networking][3] and [GitLab][4] over the past few years. Below, we're sharing some things we've learned that we hope will help make documentation a first-class citizen in your open source project.
|
||||
|
||||
1. **Value contributions to documentation just as much as code contributions:** A lot of the focus in many open source communities tends to be on code. One easy way to make sure documentation contributions are valued by everyone is to give equal credit to documentation and code in your community metrics. It should not matter whether a commit, merge request, or pull request is for code or documentation. In addition, when you do community recognition, include key accomplishments by the people who contribute to documentation.
|
||||
|
||||
2. **Put documentation and code in the same project repo:** We highly recommend that a project's code and documentation both reside in the same repository. (A good way is to make `/doc` or `/docs` a top-level directory in the repository.) For one, this makes documentation easy for anyone to find. More importantly, your documentation will be on equal footing as code and other project resources when everything is in the same repository.
|
||||
|
||||
3. **Make documentation a requirement for a merge or release milestone:** If your project has a lengthy release cycle (e.g., three to six months or more), we highly recommend having interim checkpoints for documentation (like this [example][5] from the ONAP community). This ensures documentation work is not put off until right before the release, and instead, everyone works on documentation throughout the release cycle. If it's feasible for your community, you could make documentation a required step for all code contributions that will impact users (see this [example][6] from GitLab).
|
||||
|
||||
4. **Have a consistent contribution process for code and documentation:** We also recommend having a consistent contribution process and using the same toolchains for code and documentation. As we noted earlier, many new community members start contributing by working on documentation, as you often don't need deep technical knowledge of the software to get started. It's good for new contributors to onboard in the community by getting familiar with the contribution workflow and meeting other community members. If these new contributors later want to get involved in other parts of the project (including code), you want the toolchains and contribution process to be familiar. Otherwise, they will need to go through another onboarding process, which creates an unnecessary hurdle for contributors. If your code and documentation have different contribution processes, you may risk creating an impression that documentation is less than a first-class citizen compared to code.
|
||||
|
||||
5. **Have well-documented processes for contributing to documentation:** This may seem obvious, but it's easy to neglect. Since documentation is a good entry point for new contributors, you want to lower the barrier to entry as much as possible. Having good documentation on the contribution workflow, how to get started, where to find issues to work on, how to get help, and more will go a long way to helping new contributors feel welcome and get involved in your community.
|
||||
|
||||
|
||||
|
||||
|
||||
### What else?
|
||||
|
||||
Do you have other tips for making documentation a first-class citizen in open source communities? If so, please share them in the comments.
|
||||
|
||||
* * *
|
||||
|
||||
*This article is based on [Ensuring that documentation Is a first-class citizen in open source projects][7] *presented *at Open Source Summit North America in June 2020. *
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/8/documentation-open-source-projects
|
||||
|
||||
作者:[Ray Paik][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/rpaik
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/files_documents_paper_folder.png?itok=eIJWac15 (Files in a folder)
|
||||
[2]: https://opensource.com/resources/what-open-source
|
||||
[3]: https://www.linuxfoundation.org/projects/networking/
|
||||
[4]: https://about.gitlab.com/
|
||||
[5]: https://wiki.onap.org/display/DW/Guilin+Documentation
|
||||
[6]: https://docs.gitlab.com/ee/development/contributing/merge_request_workflow.html#definition-of-done
|
||||
[7]: https://sched.co/c3SY
|
@ -0,0 +1,55 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (You don't need a computer science degree to work with open source software)
|
||||
[#]: via: (https://opensource.com/article/20/8/learn-open-source)
|
||||
[#]: author: (Jim Hall https://opensource.com/users/jim-hall)
|
||||
|
||||
You don't need a computer science degree to work with open source software
|
||||
======
|
||||
Open source makes software knowledge accessible to anyone, so formal
|
||||
training isn't the only path to a technology career.
|
||||
![Stack of books for reading][1]
|
||||
|
||||
I am mostly a self-taught programmer. When I was growing up in the late 1970s, our elementary school had a small resource room with an Apple II computer. My brother and I fell into a group of friends that liked computers, and we all helped each other learn the system.
|
||||
|
||||
We showed such promise that our parents bought us an Apple II+ clone called the Franklin ACE 1000. My brother and I taught ourselves how to program in AppleSoft BASIC. Our parents bought us books, and we devoured them. I learned every corner of BASIC by reading about something in the book, then writing a practice program. My favorite pastime was writing simulations and games.
|
||||
|
||||
I stayed with BASIC for a long time. Our next computer was an IBM PC clone with a version of BASIC on it. Much later, MS-DOS 5 introduced QBasic, which was a modern version of BASIC that finally eliminated line numbers.
|
||||
|
||||
I began to learn other programming languages when I entered university. I was a physics student, and as part of our numerical analysis prerequisite, we had to learn Fortran. Having already learned BASIC, I thought Fortran was pretty easy to pick up. Fortran and BASIC were very similar, although Fortran was more limited in my experience.
|
||||
|
||||
My brother was a computer science major at a different university, and he introduced me to the C programming language. I immediately loved working in C! It was a straightforward programming language that gave me a ton of flexibility for writing useful programs. But I didn't have room in my degree program to take a class that didn't apply to my physics major. So, instead, I taught myself C by reading books and combing through the library reference guide. Each time I wanted to learn a new topic, I looked it up in the reference guide and wrote a practice program to exercise my new knowledge.
|
||||
|
||||
My early use of C was writing new utilities to expand MS-DOS. I used Unix on campus, but my computer at home mostly ran MS-DOS. I wanted MS-DOS to have similar enhanced command-line features that Unix offered, so I wrote my own utilities to give me the added functionality.
|
||||
|
||||
I suppose my first tools were pretty simple programming exercises. I used programs like Unix cat or DOS TYPE to display the contents of text files, with extra command-line options to add line numbers, convert tabs to spaces, and the like. Or I'd use a program like Unix clear or DOS CLS to clear the screen, but also set the colors to something other than the usual white-on-black text. And I wrote a few new utilities to help me with my studies, like a program to find common errors in a Fortran source file, a utility to organize files in a directory, a filter to convert nroff files to LaTeX format, and a program to fit a straight line through x and y data points.
|
||||
|
||||
Armed with this limited experience in C programming, I tackled my first big open source project. It turns out you can accomplish a lot if you don't know what you don't know and have a passion for a project. That's how I created the [FreeDOS Project][2] in 1994.
|
||||
|
||||
Since then, I've written, maintained, or otherwise contributed to dozens of open source projects on FreeDOS, Linux, and Big Unix. My first contribution was a fix to GNU Emacs so it would compile correctly on a DomainOS Unix system. I also submitted patches to an early open source C compiler specific to HP-UX, a fun artillery game with cartoony tanks, a utility to organize music on an iPod, and other Unix and Linux programs. On FreeDOS, I wrote much of the underlying code libraries we used at the time, including an implementation of Unix catgets, so FreeDOS programs could support different spoken languages without having to be rewritten.
|
||||
|
||||
Over time, I leveraged what I'd learned to pick up other programming languages. I wrote a ton of Unix Korn shell scripts, Linux Bash scripts, and AWK scripts. I wrote small utilities in Perl, and later wrote Perl CGI and PHP pages for websites. I learned enough LISP to tweak my copy of GNU Emacs, and enough Scheme to work on a project that used GNU Guile. And I continued to write and share open source games, applications, utilities, and tools for Linux and FreeDOS.
|
||||
|
||||
And as I wrote more code, I got better at programming. Even today, I continue to learn new things and reinforce those lessons by [teaching others][3]. I'm always trying new things out.
|
||||
|
||||
And that's my lesson. You don't have to be formally trained in computer science or hold a CS degree to contribute to open source software. Find your passion, and you can figure out the rest on your own. All that matters is that you love doing what you do and that you're willing to share your contribution with others.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/8/learn-open-source
|
||||
|
||||
作者:[Jim Hall][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/jim-hall
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/books_read_list_stack_study.png?itok=GZxb9OAv (Stack of books for reading)
|
||||
[2]: https://opensource.com/article/17/10/freedos
|
||||
[3]: https://opensource.com/article/20/7/teaching-c
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,175 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Do math in the Linux shell with GNU bc)
|
||||
[#]: via: (https://opensource.com/article/20/7/bc-math)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Do math in the Linux shell with GNU bc
|
||||
======
|
||||
Do better math in the shell with bc, a mathematical language for
|
||||
advanced calculation.
|
||||
![old school calculator][1]
|
||||
|
||||
Most [POSIX][2] systems come with [GNU bc][3], an arbitrary precision numeric processing language. Its syntax is similar to C, but it also supports interactive execution of statements and processing data from standard in (`stdin`). For that reason, it's often the answer to the question, "How do I do math in the Linux shell?" This style of response is common online:
|
||||
|
||||
|
||||
```
|
||||
$ echo "1+1" | bc
|
||||
2
|
||||
```
|
||||
|
||||
While that's perfectly valid, few users argue it's elegant compared to something more intuitive, such as:
|
||||
|
||||
|
||||
```
|
||||
$ 1+1 #this does not work
|
||||
2
|
||||
```
|
||||
|
||||
The interactive mode is a little easier:
|
||||
|
||||
|
||||
```
|
||||
$ bc
|
||||
1+1
|
||||
2
|
||||
quit
|
||||
$
|
||||
```
|
||||
|
||||
But interactive modes don't always fit the desired and intuitive workflow of something simple, like just typing in the calculation you want. For this, I suggest Bluebat's [calculator in pure Bash][4].
|
||||
|
||||
What bc actually provides is a mathematical language for advanced calculation.
|
||||
|
||||
### Advanced functions with mathlib
|
||||
|
||||
On its own, `bc` provides basic math functions. You can test them in the interactive mode:
|
||||
|
||||
|
||||
```
|
||||
$ bc
|
||||
3^2
|
||||
9
|
||||
(3^2)*(9)/3
|
||||
27
|
||||
```
|
||||
|
||||
Use the `--mathlib` option to gain advanced functions, including sine, cosine, tangent, and more. In the interactive mode, you can test some of them. Here's the cosine of 90:
|
||||
|
||||
|
||||
```
|
||||
c(90)
|
||||
-.44807361612917015236
|
||||
```
|
||||
|
||||
The sine of 9:
|
||||
|
||||
|
||||
```
|
||||
s(9)
|
||||
.41211848524175656975
|
||||
```
|
||||
|
||||
### Creating your own bc functions
|
||||
|
||||
You can also create your own functions in bc. Function definitions start with the `define` keyword and are enclosed with braces. Here is a simple function entered into an interactive session that returns whatever number it's given:
|
||||
|
||||
|
||||
```
|
||||
$ bc
|
||||
define echo(n) {
|
||||
return (n);
|
||||
}
|
||||
```
|
||||
|
||||
In the same interactive session, test it out:
|
||||
|
||||
|
||||
```
|
||||
echo(2)
|
||||
2
|
||||
echo(-2)
|
||||
-2
|
||||
```
|
||||
|
||||
### If statements in bc
|
||||
|
||||
The bc language also has a variety of control statements, the simplest of which is if/else. The syntax may appear familiar at first glance, but there are subtleties in how braces are handled. Note that the _else_ clause of an if-statement is enclosed in braces, while the _then_ clause is not, but both are terminated with a semicolon. Here's a function to find the absolute value of a number _n_:
|
||||
|
||||
|
||||
```
|
||||
define abso(n) {
|
||||
if ( n > 0 ) return (n);
|
||||
{ return (-n); }
|
||||
}
|
||||
```
|
||||
|
||||
In the same interactive session, test it out:
|
||||
|
||||
|
||||
```
|
||||
abso(-5)
|
||||
5
|
||||
abso(5)
|
||||
5
|
||||
```
|
||||
|
||||
### Importing data into bc
|
||||
|
||||
Working in an interactive session is tolerable for quick calculations and experimentation, but you lose your data when you quit, and it's difficult to edit when you make mistakes. Fortunately, bc can load variables and functions from external files.
|
||||
|
||||
Here's a file containing two variables (`sol` and `foo`) and a custom `abso` function to find an absolute value:
|
||||
|
||||
|
||||
```
|
||||
sol=299792458
|
||||
|
||||
foo=42
|
||||
|
||||
define abso(n) {
|
||||
if ( n > 0 ) return (n);
|
||||
{ return (-n); }
|
||||
}
|
||||
```
|
||||
|
||||
Save this into a file called `bcvars.bc`, so you can import it into a bc interactive session:
|
||||
|
||||
|
||||
```
|
||||
$ bc bcvars.bc
|
||||
foo
|
||||
42
|
||||
sol
|
||||
299792458
|
||||
abso(-23)
|
||||
23
|
||||
```
|
||||
|
||||
### Power-up your math with bc
|
||||
|
||||
The bc language is relatively simple, provided you know enough math to construct the equation for whatever you're trying to accomplish. While bc by default provides useful basic functions and allows you to create your own, you can reduce your workload by standing on the shoulders of giants. Files loaded with new functions, both for mathematic fundamentals as well as for specific tasks (for instance, calculating compound interest), are available from [GNU bc page][5], and [full documentation][6] for bc is available.
|
||||
|
||||
If you're interested in doing better math in a shell, try bc. It won't turn you into a mathematics genius, but it just might make it easier to become one.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/7/bc-math
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/math_money_financial_calculator_colors.jpg?itok=_yEVTST1 (old school calculator)
|
||||
[2]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
|
||||
[3]: https://www.gnu.org/software/bc/
|
||||
[4]: https://raw.githubusercontent.com/bluebat/.bash/master/bashbc.sh
|
||||
[5]: http://phodd.net/gnu-bc/
|
||||
[6]: https://www.gnu.org/software/bc/manual/html_mono/bc.html
|
@ -0,0 +1,92 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (5 reasons to run Kubernetes on your Raspberry Pi homelab)
|
||||
[#]: via: (https://opensource.com/article/20/8/kubernetes-raspberry-pi)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
5 reasons to run Kubernetes on your Raspberry Pi homelab
|
||||
======
|
||||
A new free eBook offers step-by-step instructions for creating a private
|
||||
cloud at home, including what you can do with it when you're done.
|
||||
![Ship captain sailing the Kubernetes seas][1]
|
||||
|
||||
There's a saying about the cloud, and it goes something like this: _The cloud is just somebody else's computer._ While the cloud is actually more complex than that (it's _a lot_ of computers), there's a lot of truth to the sentiment. When you move to the cloud, you're moving data and services and computing power to an entity you don't own or fully control. On the one hand, this frees you from having to perform administrative tasks you don't want to do, but, on the other hand, it could mean you no longer control your own computer.
|
||||
|
||||
This is why the open source world likes to talk about an [_open hybrid cloud_][2], a model that allows you to choose your own infrastructure, select your own OS, and orchestrate your workloads as you see fit. However, if you don't happen to have an open hybrid cloud available to you, you can create your own—either to help you learn how the cloud works or to serve your local network.
|
||||
|
||||
Building your own cloud requires at least three Raspberry Pi units, an Arm Linux distribution to serve as an OS, and Kubernetes to help you manage the containers your cloud will run. Chris Collins explains every step you need to take to make this happen in our new [eBook][3]. If you've ever built an array of distributed computing nodes, you'll probably be surprised at how simple it is. Sooner than you expect, you'll reach the end of the installation, and you'll inevitably be faced with this question:
|
||||
|
||||
Now what?
|
||||
|
||||
What's the real-world application of a private cloud running on tiny computers in your office? What do you need Kubernetes for, anyway? I used to ask myself the same questions, and I've come up with enough answers to justify a minor investment in a spare Raspberry Pi or two and the time it takes to follow the instructions in Chris' eBook. Here are some ideas for you.
|
||||
|
||||
### Network-attached storage for your home
|
||||
|
||||
If you're a hobbyist just looking to try out the latest tech, one of the easiest entry points is improving your network. Since the Raspberry Pi was released, I've never been without a home server—even during the times my home was just a rented room in the suburbs. My home networks weren't always very complicated, but they ran a few services that I enjoyed having available, so it suited me.
|
||||
|
||||
By following along with Chris' eBook, I've recently added Kubernetes and a few nodes to my network, which give me the ability to add any number of services. I've finally got Network Filesystem (NFS) running, so my partner and I have an easy backup plan and can access shared files as if they existed locally on any computer we're using. I'm also running the open source [Kodi media server][4], so we can watch movies, listen to music, and view photos (all stored on the NFS share) anywhere in the house. A [Nextcloud][5] installation makes collaboration easy, and it also helps us keep in touch with family members in other countries without resorting to the likes of Facebook.
|
||||
|
||||
In short, Kubernetes and the many container images available for easy installs have transformed my local network into my own personal internet or supercomputer. It doesn't provide all services for all people, but it provides exactly the services I want for the people who I want to have access.
|
||||
|
||||
If you're duplicating media or applications across several devices or building a home server, you should consider a Kubernetes cluster. It's easy to scale for power and storage, it's easy to maintain, and it's a lot of fun.
|
||||
|
||||
### Education and upskilling
|
||||
|
||||
Are you considering a career in IT? Are you already in IT but want to grow as a professional? The cloud is a powerful model, and Kubernetes is an easy way to wrangle a lot of potential power. The more you learn about these concepts, the better prepared you'll be to move up in your career.
|
||||
|
||||
One of the most frustrating aspects of the cloud in its early days was its inaccessibility. If you didn't own racks of servers, it was difficult to gain experience administering and maintaining a cloud infrastructure. Thanks to open source projects like [Kubernetes][6], [OKD][7], [LXC][8], and [Podman][9], building your own cloud has become possible. Thanks to the Raspberry Pi and other Arm-based system-on-a-chip (SoC) computers, it's also affordable.
|
||||
|
||||
### Web server
|
||||
|
||||
The internet is one of the most accessible entry points into modern technology. Since the '90s, regular folk have wandered into the strange world of computing by reading HTML in a desperate attempt to understand how to put an animated GIF onto a Myspace or Geocities page. A natural progression from rudimentary HTML and CSS is to run a web server. Admittedly, a Kubernetes cluster probably is overkill for a personal site, but it's a great project to become familiar with how Kubernetes pods work and why they're important. It's also a great way to learn about [routing][10] and load balancing.
|
||||
|
||||
### Containers
|
||||
|
||||
Linux containers have changed IT and computing as a whole. The original [LXC][11] toolset enabled and inspired hugely popular technologies like Docker, Flatpak, Kubernetes, Podman, and more. Containerization is a new model of running code that's showing up on operating systems for desktops and mobile devices.
|
||||
|
||||
The problem is, containers are _different_ from what most users are accustomed to. Traditionally, binaries were compiled according to the operating systems, they were linked to locally available libraries, and they generally had access to everything on the hard drive. [Containers are different][12]. They're miniature runtime environments with binaries run within them, linked to other libraries in the container, and it's all kept separate from the host system unless it's granted a specific exemption. Furthermore, a container is ephemeral. You can create a container and dispose of it arbitrarily. Running a service in a container is a great way to learn how data can be persistent in an environment designed to end and respawn at any moment.
|
||||
|
||||
As painful as that learning curve can be, discovering how easy containerized apps are to install opens a whole new world of possibilities. You can run the [Grafana][13] dashboard, the [Prometheus][14] monitoring software, Discourse, Nextcloud, and a dozen others from prebuilt container definitions or [Helm charts][15].
|
||||
|
||||
### Web development
|
||||
|
||||
If you're a developer delivering apps for the web, [Kubernetes offers many benefits][16]. It can transform your workflow, and most importantly, it can help make your apps resilient. When you're developing for the cloud, you leverage [the best principles of microservices][17] in the context of containers, and you're able to use the advantages of distributed computing, filesystems, and databases.
|
||||
|
||||
### Try Kubernetes yourself
|
||||
|
||||
If you've learned [the basics][18] of Kubernetes, now's the time to take your knowledge a step further with your very own private cloud. Download our [**free eBook**][3] and start using Kubernetes today. You never know where it will take you.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/8/kubernetes-raspberry-pi
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/ship_captain_devops_kubernetes_steer.png?itok=LAHfIpek (Ship captain sailing the Kubernetes seas)
|
||||
[2]: https://www.redhat.com/en/topics/cloud-computing/what-is-hybrid-cloud
|
||||
[3]: https://opensource.com/downloads/kubernetes-raspberry-pi
|
||||
[4]: http://kodi.tv
|
||||
[5]: https://opensource.com/article/17/5/next-big-challenge-open-source-rich-collaboration-software
|
||||
[6]: https://kubernetes.io
|
||||
[7]: https://www.okd.io
|
||||
[8]: https://linuxcontainers.org/lxc/getting-started
|
||||
[9]: http://podman.io
|
||||
[10]: https://opensource.com/article/20/3/kubernetes-traefik
|
||||
[11]: https://opensource.com/article/18/11/behind-scenes-linux-containers
|
||||
[12]: https://opensource.com/article/19/6/kubernetes-potential-run-anything
|
||||
[13]: https://opensource.com/article/19/2/deploy-influxdb-grafana-kubernetes
|
||||
[14]: https://opensource.com/article/19/11/introduction-monitoring-prometheus
|
||||
[15]: https://opensource.com/article/20/5/helm-charts
|
||||
[16]: https://opensource.com/article/19/10/kubernetes-complex-business-problem
|
||||
[17]: https://opensource.com/article/19/11/microservices-cheat-sheet
|
||||
[18]: https://opensource.com/article/19/6/kubernetes-basics
|
@ -0,0 +1,173 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Do math in the Linux shell with GNU bc)
|
||||
[#]: via: (https://opensource.com/article/20/7/bc-math)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
使用 GNU bc 在 Linux Shell 中进行数学运算
|
||||
======
|
||||
在 shell 中使用 bc 更好地做算数,它是一种用于高级计算的数学语言
|
||||
![old school calculator][1]
|
||||
|
||||
大多数 [POSIX][2] 系统带有 [GNU bc][3],这是一种任意精度的数字处理语言。它的语法类似于 C,但是它也支持交互式执行语句和处理来自标准输入(`stdin`)的数据。因此,它通常是以下问题的答案:“我如何在 Linux shell 中进行数学运算?”这种回应方式在网上很常见:
|
||||
|
||||
|
||||
```
|
||||
$ echo "1+1" | bc
|
||||
2
|
||||
```
|
||||
|
||||
尽管这是完全正确的,但很少有用户认为,与更直观的方式相比,它很优雅,例如:
|
||||
|
||||
|
||||
```
|
||||
$ 1+1 #this does not work
|
||||
2
|
||||
```
|
||||
|
||||
交互模式要容易一些:
|
||||
|
||||
|
||||
```
|
||||
$ bc
|
||||
1+1
|
||||
2
|
||||
quit
|
||||
$
|
||||
```
|
||||
|
||||
但是交互模式并不总是适合简单计算想要的直观工作流,比如直接输入你想要的计算。因此我推荐 Bluebat 的[纯 Bash 计算器][4]。
|
||||
|
||||
bc 实际上提供了一种用于高级计算的数学语言。
|
||||
|
||||
### 含高级函数的 mathlib
|
||||
|
||||
`bc` 本身提供了基本的数学函数。你可以在交互式模式下测试它们:
|
||||
|
||||
```
|
||||
$ bc
|
||||
3^2
|
||||
9
|
||||
(3^2)*(9)/3
|
||||
27
|
||||
```
|
||||
|
||||
使用 `--mathlib` 选项获取高级函数,包括正弦、余弦、正切等。在交互式模式下,你可以测试其中一些。下面是 90 度的余弦:
|
||||
|
||||
|
||||
```
|
||||
c(90)
|
||||
-.44807361612917015236
|
||||
```
|
||||
|
||||
9 的正弦:
|
||||
|
||||
|
||||
```
|
||||
s(9)
|
||||
.41211848524175656975
|
||||
```
|
||||
|
||||
### 创建你自己的 bc 函数
|
||||
|
||||
你还可以在 bc 中创建自己的函数。函数定义以 `define` 关键字开始,并用大括号括起来。下面是一个输入到交互式会话中的简单函数,它返回给它的任意数字:
|
||||
|
||||
|
||||
```
|
||||
$ bc
|
||||
define echo(n) {
|
||||
return (n);
|
||||
}
|
||||
```
|
||||
|
||||
在同一个交互式会话中,测试一下:
|
||||
|
||||
|
||||
```
|
||||
echo(2)
|
||||
2
|
||||
echo(-2)
|
||||
-2
|
||||
```
|
||||
|
||||
### bc 中的 if 语句
|
||||
|
||||
bc 语言还有各种控制语句,其中最简单的是 if/else。语法乍一看可能很熟悉,但在如何处理大括号方面有些不同。请注意,if 语句的 _else_ 子句包含在大括号中,而 _then_ 子句不是,但两者都用分号终止。下面是一个返回数字 _n_ 的绝对值的函数:
|
||||
|
||||
|
||||
```
|
||||
define abso(n) {
|
||||
if ( n > 0 ) return (n);
|
||||
{ return (-n); }
|
||||
}
|
||||
```
|
||||
|
||||
在同一个交互式会话中,测试一下:
|
||||
|
||||
|
||||
```
|
||||
abso(-5)
|
||||
5
|
||||
abso(5)
|
||||
5
|
||||
```
|
||||
|
||||
### 将数据导入 bc
|
||||
|
||||
使用交互式会话对于快速计算和实验是可以容忍的,但在退出时会丢失数据,并且在出错时很难编辑。幸运的是,bc 可以从外部文件加载变量和函数。
|
||||
|
||||
下面是一个包含两个变量(`sol` 和 `foo`)的文件,以及一个用于查找绝对值的自定义 `abso` 函数:
|
||||
|
||||
|
||||
```
|
||||
sol=299792458
|
||||
|
||||
foo=42
|
||||
|
||||
define abso(n) {
|
||||
if ( n > 0 ) return (n);
|
||||
{ return (-n); }
|
||||
}
|
||||
```
|
||||
|
||||
将它保存到名为 `bcvars.bc` 的文件中,以便导入 bc 交互式会话:
|
||||
|
||||
|
||||
```
|
||||
$ bc bcvars.bc
|
||||
foo
|
||||
42
|
||||
sol
|
||||
299792458
|
||||
abso(-23)
|
||||
23
|
||||
```
|
||||
|
||||
### 使用 bc 助力你的数学
|
||||
|
||||
bc 语言相对简单,前提是你知道足够的数学知识来构造任何你想完成的方程。虽然 bc 默认提供了有用的基本函数,并允许你创建自己的函数,但你可以通过站在巨人的肩膀上来减少工作量。加载了用于数学基础知识和特定任务(例如,计算复利)的新函数的文件可从 [GNU bc 页][5]获得,同时也可获得 bc [完整文档][6]。
|
||||
|
||||
如果你有兴趣在 shell 里更好地处理数学,试试 bc 。它不会使你成为数学天才,但它可能会让过程更简单。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/7/bc-math
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/math_money_financial_calculator_colors.jpg?itok=_yEVTST1 (old school calculator)
|
||||
[2]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
|
||||
[3]: https://www.gnu.org/software/bc/
|
||||
[4]: https://raw.githubusercontent.com/bluebat/.bash/master/bashbc.sh
|
||||
[5]: http://phodd.net/gnu-bc/
|
||||
[6]: https://www.gnu.org/software/bc/manual/html_mono/bc.html
|
Loading…
Reference in New Issue
Block a user