Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the pitfalls of Shell script programming in linux

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about what the Shell scripting pitfalls are in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Shell scripts are great, and you can write useful things very easily. It's even like this stupid command:

# name it with the word containing Go: $grep-I ^ go / usr/share/dict/* | cut-d:-f2 | sort-R | head-n1goldfish

If you use other programming languages, it takes more brainpower to implement it in multiple lines of code, such as Ruby:

Puts (Dir ['/ usr/share/dict/*-english'] .map do | f | File.open (f) .readlines .select {| l | l [0.. 1] .downcase = = 'go'} end.flatten.sample.chomp)

The Ruby version of the code is not that long, nor is it complex. But the shell version is so simple that I don't even have to actually test it to make sure it's correct. For the Ruby version, I'm not sure it won't go wrong. I have to test it. And it's twice as long and looks more complicated.

That's why people use the Shell script, which is simple but practical. Here is another example:

Curl https://nl.wikipedia.org/wiki/Lijst_van_Nederlandse_gemeenten | grep'^

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report