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 practical Shell scripts?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what are the practical Shell scripts". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "what are the practical Shell scripts"?

1 remote copy of a special file name

The scp command is often used to copy files between servers in the command format:

(1) scp filename [user@] host:dir

(2) scp [user@] host:dir1/filenamedir2

Format (1) copy the local file filename to the dir directory of the remote server host, and format (2) copy the file filename under the dir1 directory of the remote server host to the local dir2 directory.

If the file name you copied contains special characters, such as ecs-eos-base:1.0.tar, colons: belong to special characters. Directly use the command in format (1) to copy, and the command recognizes ecs-eos-base as the host name, and the command runs with an error, as follows:

[root@PHY91 docker] # scp ecs-eos-base:1.0.tar root@PHY94:/root/docker/

Ssh: Could not resolve hostname ecs-eos-base: Temporary failure in name resolution

Use. / at this time to indicate that the current directory can resolve the error. The command is as follows:

[root@PHY91 docker] # scp. / ecs-eos-base:1.0.tar root@PHY94:/root/docker/

Ecs-eos-base:1.0.tar 100% 84MB 172.7MB/s 00:00

Using. / for the current directory, the scp command does not recognize ecs-eos-base as the host name.

2 Base64 encoding and decoding

In the Centos or Redhat Linux operating system, if you want to encode and decode a string in Base64, you can simply use the base64 command.

(1) coding

[root@PHY91 ~] # echo "PHY91" | base64

UEhZOTEK

(2) Decoding

[root@PHY91 ~] # echo "UEhZOTEK" | base64-d

PHY91

Base64 can not only encode and decode strings, but also encode and decode the contents of files. The-d parameter represents decoding.

The command to encode and decode the file is as follows:

[root@PHY91 test] # echo "12345" > test.txt

[root@PHY91 test] # base64 test.txt

MTIzNDUK

[root@PHY91 test] # base64 test.txt > test2.txt

[root@PHY91 test] # more test2.txt

MTIzNDUK

[root@PHY91 test] # base64-d test2.txt

12345

The realization of self-growth of version 3.

When using docker build to build an application image, the image version number of each build will be increased by 1 to facilitate image version management. You can use a script to increase the version number by 1, and first create a version.txt file with the following contents:

[eos@host-132 eos] $more version.txt

1.0.0

The command to get the version number is as follows:

Version=cat version.txt

The version number is assigned to the version variable.

The version number is automatically increased by 1, and the script command is as follows:

Echo $version | awk-funding.'{print ($1 "." $2 "." ($331));}'> version.txt

Command description:

(1) use the awk command with the delimiter as the dot. "

(2) $1 and $3 are the first and second numbers of the version number, respectively.

(3) $3 million 1 means that the version number is increased by 1.

4 sed configure the running environment

In a web application project with complete separation of movement and movement, the front end can deploy static resources using nginx. The benchmark URL (baseUrl) of the front end code of the project needs to be modified according to different running environments (development, test, production). For example, the js code for baseUrl assignment is as follows:

Define (["jquery"], function ($) {

Return {at this point, I believe you have a deeper understanding of "what practical Shell scripts are". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report