Table of Contents
回复内容:
Home Backend Development Python Tutorial 会一门脚本语言,学 bash 就显得浪费时间?

会一门脚本语言,学 bash 就显得浪费时间?

Jun 06, 2016 pm 04:22 PM
bash else if ruby

首先bash虽然有if_else,可以调系统命令。但是许多局限性比如不支持多线程,没有库。所以会py或者ruby再去学bash,这是没必要 的。

回复内容:

日常工作,很多工作都是很琐碎 很细节的,你想不到你会遇到什么具体的小任务。
这时,你总不能打开vim 写个python脚本。
很可能还没写完#! ,shell 可能已经搞定了任务了。

所以会shell,熟练掌握各种命令,会sed awk,给日常工作带来很大的效率提升。
相信每一个Linux下的讨饭吃的程序员都深有体会。

琐碎任务一次性的任务交给shell; 注定要扩展,代码量不小,要维护的任务交给python.
需要效率的工作交给C。从来就不冲突。 学习 bash,并不仅仅是学习 bash 本身的语法,而是要去学习一下各种命令行工具的使用方式……
说到底,一切都是为了提高生产效率啊! 有py shell和ruby shell等等一大堆东西 另外一个角度看, 是shell script 让你拥有system utility的能力, 所有已安装的程序都洗干净了排着队等你调戏。sed, awk, kill, cat, ps, mkdir, rm, rsync, ..... 数都数不过来的别人幸苦调教好的漂亮姑娘,而*nix与生俱来的特性(redirection, pipe ...)又让它们可以很好的协同工作(因此do one thing, well) 。

如果你的程序有很多custom logic, 需要面向复杂些的数据结构,shell 的笨拙就会比较明显,这个时候就去找sexy的Python吧。 用Linux,bash还是要懂的。但是bash的语法确实有点奇怪(通常都是把c的语法当做是标准语法,所以说一门语言语法奇怪,就是说这门语言跟c的语法规则相去甚远),所以要想写好用的script,最好是学一门基于c的比较现代的语言。我现在用的是Python,然后需要执行bash的命令,就调用os,基本上所以的bash命令都可以用os.system("")这种方式运行。迄今为止,我唯一发现不能用os.system运行的就是 cd. Python中可以用os.chdir("")来实现 bash 的 cd. 今天服务器异地迁徙,我的shell脚本成功运维了500台服务器,包括对对等拷贝虚拟机配置按IP修改,组件启停,日志备份,服务器运行状态监控。shell起码不需要python解释器,代码上又异常优雅,你觉得shell不舒服,还是受到传统命令式编程的框架桎梏。每次打开vim看到花花绿绿又十分简洁的shell都让人陶醉,谁他妈再让我写Java或者python 去搞运维我就跟谁急 如果你是写需要长期运营的脚本,强烈推荐用python(或ruby等其他),倒不是说这样会更快,更方便,而是可读和可维护会好些,类似的还有makefile等,bash、sed、awk和make中那些奇怪的语法和符号的学习维护成本真的不如python中多啰嗦几句,而且用python可以做到一招通杀大多数需求,不然你的脑子得在bash,sed,awk之间来回切换
但如果你的脚本可能只是运行个一次,或临时一条命令,用bash还是很方便的
所以,bash不用很精通,但要保证会到一定水平,日常的工作区分来做
然而你也不可避免会碰到阅读维护其他人代码的情况,所以还是大致要了解下,比如if的语法,至于if里面的-a -o -f之类的可以问度娘了 当然不是浪费时间了(不然你让我们这种会用shell的情何以堪...)

假设路上有一坨屎, 你是用铲子(shell)铲掉, 还是开个铲车(python)来搞?
当然, 也会有粪坑, 但是大部分情况下是路上横躺了一坨屎, 极有可能还是别人丢过来的.

而且shell也没那么恶心嘛. 真正的脚本呢. 在*nix服务器下调试程序,查看程序debug日志或者运行日志,如果不懂shell,蛋疼死你 bash和命令行都设计拙劣。但现状如此,你不学就寸步难行。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to write if in c language to judge multiple conditions How to write if in c language to judge multiple conditions Mar 25, 2024 pm 03:24 PM

In C language, if statement is usually used to execute a specific block of code based on a single condition. However, multiple conditions can be combined to make a determination using logical operators such as &&, ||, and !. Including using logical AND (&&) to judge multiple conditions, using logical OR (||) to judge at least one condition, using logical NOT (!) to judge the negation of a single condition, as well as nesting if statements and using parentheses to clarify priority.

Different ways to run shell script files on Windows Different ways to run shell script files on Windows Apr 13, 2023 am 11:58 AM

Windows Subsystem for Linux The first option is to use Windows Subsystem for Linux or WSL, which is a compatibility layer for running Linux binary executables natively on Windows systems. It works for most scenarios and allows you to run shell scripts in Windows 11/10. WSL is not automatically available, so you must enable it through your Windows device's developer settings. You can do this by going to Settings > Update & Security > For Developers. Switch to developer mode and confirm the prompt by selecting Yes. Next, look for W

Ubuntu Bash performance comparison: Ubuntu vs. Win10 Anniversary Edition Ubuntu Bash performance comparison: Ubuntu vs. Win10 Anniversary Edition Jan 04, 2024 pm 09:36 PM

At the beginning of this year, when Microsoft and Canonical released Windows 10 Bash and Ubuntu user space, I tried to do some preliminary performance tests on Ubuntu on Windows 10 compared to native Ubuntu. This time I published more about the benchmark comparison between native pure Ubuntu and Windows 10. The Linux subsystem test for Windows completed all tests and was released with the Windows 10 Anniversary Update. The default Ubuntu user space is still Ubuntu14.04, but it can be upgraded to 16.04. So the test is first tested on 14.04, and after completion, the system will be upgraded to 16.04

Five Little-Known Modern Bash Scripting Techniques Five Little-Known Modern Bash Scripting Techniques Jun 26, 2023 pm 08:36 PM

Programmers often use the Bash command language to create shell scripts to automate manual tasks. For example, they create Bash scripts for various configurations, file operations, generating build results, and various DevOps-related activities. Almost all Unix-like or Unix-based operating systems provide users with a pre-installed Bash interpreter, so we can use Bash to write more portable automation scripts. As we already know, Bash scripting refers to writing a series of commands using the syntax of the Bash command language, built-in Bash commands, and core operating system CLI programs such as GNU Core Tools. A standard and old-fashioned Bash script usually executes some commands and displays plain text on the terminal

Bash program to find A raised to the power B? Bash program to find A raised to the power B? Aug 30, 2023 pm 09:01 PM

Here we will see how to get the number A raised to the power B using a bash script. The logic is simple. We have to use the "**" operator or the power operator to do this. Let us see the following program to understand this concept clearly. Example#!/bin/bash#GNUbashScripta=5b=6echo "$(($a**$b))" output 15625

How to use if nested statements in MySQL stored procedures How to use if nested statements in MySQL stored procedures May 26, 2023 pm 12:07 PM

1. Introduction to if statement The if statement is a branching structure statement that performs different operations according to conditions. The if statement usually consists of a conditional expression and one or more statements. If the value of the conditional expression is true, then the statements in the if statement are executed; otherwise, the if statement block is skipped. The syntax of the if statement is as follows: if(condition)thenstatement;elsestatement;endif; where condition is the conditional expression and statement is the SQL statement that needs to be executed. 2. Introduction to if nested statements An if nested statement refers to nesting one or more if statement blocks within an if statement block to perform different operations based on different conditions.

In-depth analysis of the similarities and differences between Golang and Ruby In-depth analysis of the similarities and differences between Golang and Ruby Jun 01, 2024 pm 08:46 PM

The main difference between Go and Ruby is that Go is a statically typed compiled language that supports lightweight parallelism and efficient memory management, and is suitable for writing high-concurrency applications; Ruby is a dynamically typed interpreted language that supports true parallelism but memory management It requires manual control and is suitable for writing flexible web applications.

Why have Python, Ruby and other languages ​​deprecated the increment operator? Why have Python, Ruby and other languages ​​deprecated the increment operator? May 11, 2023 pm 04:37 PM

Many people may notice a phenomenon, that is, in some modern programming languages ​​​​(of course, not referring to "recent" programming languages), the increment and decrement operators have been cancelled. In other words, there is no such expression as i++ or j-- in these languages, but only i+=1 or j-=1 Such an expression. This answer will explore the background and reasons for this phenomenon from the perspective of design philosophy. Strictly speaking, it may be biased to say "i++ is disappearing", because it seems that only Python, Rust and Swift among mainstream programming languages ​​do not support the increment and decrement operators. When I first came into contact with Python, this was also

See all articles