Modern computers and operating systems provide users with limitless possibilities. However, clicking with a mouse and using graphical interface is not always the most efficient method of operation. Scripts and system shells offer alternative, often more advanced and flexible ways of working with a computer. 

While the terms “script” or “command-line shell” may sound intimidating to many, like a sentence of ten years of hard labor in the mines, the truth is that the basics of using them are accessible to anyone, who wants to deepen their knowledge of computers.

Whether you are a novice user or an experienced technology enthusiast, this article will provide you with valuable information and tips on how to make your computer more responsive to your commands. 

Understanding shells and their varieties

The term “text shell” may sound like a relic from the past. However, in reality, a text shell is an indispensable tool, that enables direct, complex, yet precise and clear interaction with the operating system.

In a world of visual icons and touch interfaces, text shells remain invaluable for those, who truly want to understand and control their computer, as well as safe time and resources, which is particularly crucial in it commercial projects. Depending on users’ preferences and needs, shells can be divided into two main families.

Graphical shells focus on visual interactions, where elements like cursors, touch, and icons take center stage. Examples of such shells include:

  • Aqua (typical for macOS)
  • Windows Shell
  • Gnome, KDE, and Unity, found in various Linux distributions and other operating systems.

On the other hand, text shells revolve around command-line input via the keyboard, often favored by IT professionals for precision and system control. Examples include:

  • Familiar to Windows users, cmd.exe and PowerShell
  • For Linux, Mac and other Unix-like, we have options like sh and its numerous variations, including popular choices like bash and zsh. In the open-source world, various derivatives of text shells allow for customization to specific requirements.

System shells and their key advantages

Graphical shells:

  • Lower entry barrier for users but at the cost of reduced functionality*
  • Capable of triggering command-line operations in response to various events, such as keyboard shortcuts.
  • Often, the graphical interface serves as a user-friendly wrapper for programs designed for text-based environments 

*It’s considerably more challenging to perform ‘power user’ actions within a graphical shell

Text shells:

  • Consistent operation across different operating systems
  • The ability to manipulate windows and programs managed by the graphical shell, provided the graphical shell offers appropriate interface
  • By adhering to communication standards, text shells make it easy to integrate your own programs and scripts with others, greatly expanding capabilities
  • Easy orchestration of multiple programs using relatively simple scripts:

👉 Unix-based systems have long enjoyed this ease of use

👉 Windows and closed-source software are increasingly supporting automation from the command line

👉 Open-source programs are also highly automatable from the shell (even if the program is primarily graphical). It’s particularly useful to familiarize oneself with the file formats supported by a given program (especially if these files are text-based) and its command-line parameters. Sometimes, alternative methods of communication with the program are available as well

💡Note: Both the advantage and disadvantage of text shells lie in their syntax

Advantage: The syntax is incredibly convenient when integrating various commands (compared to regular programming languages).

Disadvantage: Logical or arithmetic operations, complex data processing, and analysis are not particularly efficient or fast with text shell syntax. Often, the shell needs to invoke a separate program to handle data analysis. In other cases, the complexity of the syntax can be a hindrance.

So, what can you do to be more efficient?

💡Our PRO tip:

It’s often better to write a Python or Java script (starting from JDK 9, jshell is available, enabling script execution) for data processing and then connect these programs using a shell script.

Shells emerging from the unix environment

The most well-known examples are ‘bash’ and ‘zsh,’ with the latter gaining popularity recently. Each of them has its uniqueness, history, and applications, but they all share one common trait — enabling deep, text-based communication with the machine.

By getting to know these shells, you increase your chances of quickly transitioning between systems and writing universal scripts that adapt to all types of systems.

It’s valuable to understand the syntax differences between bash, zsh, and the basic sh because, at times, on stripped-down systems like embedded systems, only simple implementations like ‘ash’ are available, which don’t provide as many features as the more popular bash or the increasingly popular zsh. You can usually install more feature-rich and extensive shells, but the question is, is it worth it?”

💡Our PRO tip (for the Windows Environment)

In the Windows environment, text shells are also available by default. Characteristic of this family of systems are ‘cmd’ and ‘PowerShell.

It’s highly beneficial to familiarize yourself with the basics of both PowerShell and cmd.exe because sometimes you may not have the option to install other text shells on Microsoft systems. These two typically Windows-native tools complement each other, allowing you to work around limitations of one shell by using the other.

Scripts and commands — in theory

Commands:

In the world of text shells, we encounter two fundamental categories of commands: shell commands and system commands.

Shell commands, the first category, are specific to a particular shell and are only available within its scope. For example, the ‘cd’ command, while present in many shells, may function slightly differently depending on the specific environment.

On the other hand, system commands are independent programs installed on our system. We can execute them from any shell, and their behavior remains consistent regardless of the shell we use. This is a crucial distinction that helps us understand how we communicate with our system through a text-based interface.

💡Our PRO tip:

You can check whether a specific command is a system command using the ‘which’ command in shells similar to ‘sh.’ In PowerShell, you can use ‘gcm’ or ‘Get-Command.’

Scripts:

A script is a standardized set of steps to be executed. It can be executed manually, by typing or copying commands or automatically, by specifying a file containing an organized set of commands to run. While manual input or copying of commands is possible, the real magic happens when we use automation. Sometimes, this even comes with a pleasant sense of excitement.

1

One of the greatest advantages of text shells is the incredible ease of scripting. (However, it’s worth keeping in mind that the deeper you go into the woods, the more trees, wild animals, or even goblins you might encounter!) Everything that we enter directly into the terminal can be saved in the exact same form in a text file.

Subsequently, this file can be executed as a single command, allowing the entire set of instructions to run automatically.

This not only saves time, but also minimizes the risk of errors resulting from manual command entry. Scripts are a powerful tool in the hands of every shell user.

Why scripts are a great solution

  • In most cases, users can simply run a script without the need for manual intervention 
  • Scripts are flexible and allow modifications when the need arises 
  • They enable the preparation of a runtime environment for more complex programs, that perform additional functions 
  • Sequential execution of a set of commands guarantees significant process optimization, leading to improved efficiency and productivity
  • Automation ensures consistency and eliminates the risk of errors resulting from manual transcription of instructions, further saving time and resources

Guide to scripting for dummies 

  1. What you copy, type, or often input manually into the console – save it as a script
  2. Create scripts – even the most clumsy ones! Each one of them represents knowledge on how to tackle a specific problem: you don’t have to search the internet on how ‘if’ statements or loops work when you have an example on your computer
  3. Learn from your own work: Copy (with understanding 🙂 ) ready-made solutions from your own scripts
  4. Keep your scripts in a separate directory. Why? If a piece of code needs to do something elsewhere, it can always navigate to that path using ‘cd’ or ‘pushd/popd,’ and separate directories help maintain order
  5. Share your knowledge: Share your scripts as a repository. This not only allows you to revisit them, but also helps others benefit from your expertise.
  6. Don’t be ashamed! A script is a tool, not necessarily a finished product. It’s also a form of note-taking on how to tackle a specific problem
  7. Create directories:
    • Personal – for what’s universal.
    • Company – for company projects.
    • Client – for client projects. Sharing insights with clients also helps organize our own knowledge, and our colleagues can benefit from it
  8. Allocate 20% of your time to automate 80% of a given task — Remember! We don’t always have the time to fine-tune everything, and it’s not always worth it when creating tools for personal use
system shell in it work
2

💡Our PRO tip: 

The Baby Steps Method! 

  • Automate one step (the most annoying and simplest one) first. 
  • Then automate the next one. 
  • Try to trigger the automated steps one after the other (either as a single script or by calling other scripts).

In a technological environment, we have a range of specialized programs dedicated to performing specific tasks. These applications, optimized for particular operations, are essential tools in our arsenal.

The key to maximizing their efficiency lies in the shell, which provides seamless connectivity and integration of these tools. Understanding the role of text-based shells as a tool for efficiently connecting small programs and scripts in various languages is crucial, especially in environments where running external applications can be cumbersome.

Similarly to a carpenter, who has various hammers tailored for specific purposes, utilizing a shell allows for maximizing the benefits of combining diverse technologies, leading to improved efficiency and time savings.

  1. https://www.reddit.com/media?url=https%3A%2F%2Fpreview.redd.it%2F6ll9ab69kou51.png%3Fauto%3Dwebp%26s%3D9fec14a3398d5386c6911fcb5e462d9d57ceed48 ↩︎
  2. https://www.reddit.com/r/ProgrammerHumor/comments/g9j8c6/cries_in_powershell/ ↩︎