Неясно, имеет ли смысл все интерфейсы командной строки (CLI) там, и когда / почему их использовать

350
TheGrapeBeyond

В качестве предыстории я прилагаю умственные усилия, чтобы начать использовать интерфейс командной строки для всей своей работы в системах Windows, Mac OSX и LINUX. Это правда, что у нас гораздо больше гибкости в командной строке по сравнению с графическим интерфейсом, и я легко это вижу.

Моя проблема в том, что я быстро теряюсь в лесу терминов, CLI, этой системы, работающей с проблемами этой системы и т. Д. И т. Д. Я обычно гуглю / вики конкретную программу, но мне трудно "склеить" их все все вместе.

Я был бы признателен, если бы кто-то связал их связно.

Например: на моем Mac OSX я установил «Iterm2» в качестве интерфейса командной строки. В моей системе LINIX я понимаю, что «Терминатор» - это хороший вариант, и я планирую его использовать. Так как я также хочу использовать CLI в Windows, я установил conEmu, что до сих пор было хорошо.

Теперь ... вот где это сбивает меня с толку ...: В моей системе Windows я также установил git через mysgit. Это дает мне «gitBash». В gitBash я могу использовать команды LINUX, но не команды Windows DOS. В командной строке Windows я могу использовать команды DOS, а не команды LINUX. Однако я хотел бы использовать команды LINUX только в Windows, и поэтому (мне сказали), что Cygwin является хорошим соперником? Но почему, когда у меня есть gitBash? Это имеет значение? Могу ли я выполнить любую команду Windows через эмулятор LINUXy, например, gitBash / Cygwin?

Вы можете видеть узел, который я пытаюсь здесь развязать, я не уверен, как они все «сходятся» вместе.

Моя конечная цель - просто иметь возможность использовать команды LINUX на моем компьютере с Windows из интерфейса командной строки, без суеты, если это возможно. Я теряюсь во всех деталях.

Спасибо.

1
если у вас установлен cygwin, вам, вероятно, не нужен gitbash, который, я думаю, устанавливается при установке windows git. Я предлагаю удалить все программы Unixy, такие как Git, которые вы установили без Cygwin, затем установить их через Cygwin и придерживаться Cygwin. затем сделайте учебник по командной строке Unix. быстрый гугл дал эту ссылку: http://www.ee.surrey.ac.uk/Teaching/Unix/unix1.html Jason Lewis 9 лет назад 0
но еще лучше было бы установить правильную среду unix / linux. Вы можете сделать это на виртуальной машине, если вы не хотите использовать двойную загрузку или перезаписать установку Windows. Jason Lewis 9 лет назад 0
Спасибо @JasonLewis. Когда вы говорите «установить их через Cygwin» - я немного запутался. Насколько я знаю, мы можем установить вещи через менеджеры пакетов и тому подобное ... так что вы имеете в виду установить через cygwin? Спасибо! TheGrapeBeyond 9 лет назад 0
перезапустите команду cygwin setup.exe и выберите все, что вам нужно, чего не хватает, например, git http://stackoverflow.com/questions/15692890/running-git-through-cygwin-from-windows Jason Lewis 9 лет назад 0
http://superuser.com/questions/304541/how-to-install-new-packages-on-cygwin Jason Lewis 9 лет назад 0
У Cygwin есть свой собственный «менеджер пакетов», который вы запускаете. Они просто называют это своим установщиком. Вы не сможете запускать менеджеры пакетов типа LINUX, такие как `apt` или` ipkg` из CYGWIN, так как они слишком интегрированы в платформу. Julian Knight 9 лет назад 0

1 ответ на вопрос

2
Julian Knight

If you want to do as you've stated, I would recommend using CYGWIN.

The installer is mature and lets you choose what commands and functions you want. The defaults will get you pretty much anything you would need and then you can extend and tweak later on.

First you need to understand the difference between a Terminal and a command environment (AKA "shell"). The former allows access to a remote or local system at a low level, the latter is what is run when you connect via the terminal. This is true across all systems it is just rather better hidden in some than others. It is also worth noting that command environments contain built-in commands such as the UNIXy ls and the DOSy dir but that all systems have other "command line" tools, for example ifconfig on Linux and ipconfig.exe on Windows. It can be hard to differentiate between them but you will sometimes get tripped up when trying to execute a UNIXy command on Windows. Many of the best UNIXy command line tools are also available for Windows however, either through CYGWIN itself or via native versions. For example, the excellent exiftool that I use for batch renaming photo's on both Linux and Windows.

So you are able to replace the terminal with something more fully featured if you need it such as Lterm2 on your Mac, even Windows has a couple of alternatives though personally I wouldn't bother - more trouble than its worth.

On Windows (newer versions anyway), the default command environment is cmd.exe. It is nowhere near a featureful as it's Linux equivalent BASH. On Linux, BASH is the most common standard but you may come across others such as ASH, Korn Shell, SH and others. Windows actually provides several other command shells, the most common and powerful being PowerShell. PowerShell is so powerful because it is able to use and expose interfaces for most of the .NET libraries of which there are a great many doing all sorts of clever things. It is also Microsoft's chosen administrative shell so you use it for maintaining remote systems (both servers and clients) and even cloud services such as Office 365 and Azure. If you want to be a Windows system GURU, PowerShell is essential learning.

Back to your question though. You can easily run BASH via CYGWIN which installs it and a number of supporting commands. CYGWIN not only gives you a UNIXy way of interacting with drives, files and folders on Windows machines, it also makes available things like the Windows Registry in like manner.

Of course, there are other limits. For starters, the folder layout on Windows will always be different to Linux or MAC hosts and you will have to allow for that in any scripts that you write if you want them to work across all platforms.

You can, of course, continue to use gitBASH but you are likely to find that it doesn't have some of the commands you might expect to be available. You would have to just try it and see. If you do go down that path, when you find a missing command, you can just search for it online, it may be available as a native Windows executable and therefore should be usable from gitBASH if placed in a folder on your PATH.

Clarification 1: If you are used to Linux, you will be familiar with the fact that each distribution has a "package manager" that helps with the installation of software from recognised & (hopefully) trusted sources. They help ensure that you have all of the components and dependencies required. CYGWIN uses its "installer" for the same purpose though it is a lot simpler. Remember, most Linux tools are compiled for use on Linux (generally you need to know the type of processor you are using plus you need a load of internal dependencies from the Linux "Kernel"). To use Linux commands on Windows requires that they all get recompiled to work on a Windows platform. There is a helper library that allows this to be relatively painless (MSYS? anyway, you don't really need to know that).

You are correct in saying that Chocolatey is an attempt at a package manager for Windows. One of Windows' great failings is the lack of a single, trusted, recognised package source - or "App Store" as is now the craze for calling these things! With W8, Microsoft are trying (not all that well it has to be said) to rectify that but currently it is very limited - aimed at mobile and ModernUI apps.

However, many Windows developers have long used a tool called NUGET to help package up applications for installing on Windows. NUGET makes use of PowerShell behind the scenes. Chocolately is a set of scripts built using PowerShell and NUGET to help automate installations. It works OK but still doesn't command the widespread support it should probably have. It is easy enough to create install packages for Chocolatey, I did my first a couple of weeks ago for the Open Source Freeplane mind-mapping tool.

But, as you say, there is no connection at all between Chocolatey (using PowerShell) and BASH on CYGWIN. In your example, you will need to decide where and how you want to use VIM. If you only ever want to use it in the context of CYGWIN then install it via the CYGWIN installer. However, if you want to use it as a general Windows editor, you might be better off installing via Chocolatey. Unfortunately, there is no easy way to predict which would be best. You might even end up doing both. On the other hand, you might find some Windows applications also work fine when called from BASH and others won't!! Pain huh!

UPDATE 2: Did I mention you should stick to PowerShell!! Welcome to the world of cross platform working. CYGWIN wants its own Python package installing to satisfy internal dependencies. Using native Windows Python (such as installed through Chocolately, or manually) might work but then again might not. No easy way of telling but it is highly likely that you will hit a problem eventually if you don't have the Cygwin package installed. This is why someone else recommended using a virtual machine instead so that you keep things clean and separate.

Honestly, you might be better off accepting that you need to learn different tools for different platforms. It isn't that hard. It really depends on what you want to do. If you want to learn Linux command line, use a virtual machine. If you want to automate Windows tasks, learn PowerShell or alternatively, if you already know Python, use that instead! So many options!

Спасибо за краткое изложение Джулиан, высоко ценится. Можете ли вы расширить свой ответ по сравнению с бесчисленным количеством установщиков пакетов? Например: допустим, я установил Cygwin и, конечно, у меня есть cmd.exe. Теперь через cmd я установил шоколадку. Мне кажется, что я не могу использовать шоколад, если я был на Cygwin. Однако, если бы я должен был перейти к cmd, я мог бы использовать его, правильно? К тому же, допустим, я хочу использовать программу vim, которая, как я знаю, работает на LINUX. Теперь я могу использовать его только через CYGWIN, а не через cmd? Спасибо TheGrapeBeyond 9 лет назад 0
Обновлено по запросу! Julian Knight 9 лет назад 0
Еще раз спасибо, Джулиан, я принял ваш ответ! Кстати, с тех пор, как вы раньше использовали шоколад, могли бы вы попробовать свои силы в этом вопросе [мой] (http://superuser.com/questions/760323/chocolatey-install-of-cygwin-keeps-looping-through- места)? Большое спасибо! TheGrapeBeyond 9 лет назад 0
Джулиан - вот хороший пример: я уже установил Python34 на свою машину. Однако сейчас, в процессе установки Cygwin, он спрашивает меня, хочу ли я установить «пакет python». ... Я не знаю, что здесь делать. Почему он вообще спрашивает меня о Python? Если действительно интересно, хочу ли я Python, тогда я должен установить Python через Cygwin, чтобы я мог использовать его через Cygwin? Или, так как у меня уже есть, я должен быть в состоянии использовать это так или иначе? ...: - / TheGrapeBeyond 9 лет назад 0
Еще одно обновление. Спасибо, что приняли. Julian Knight 9 лет назад 0