In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to concatenate and merge Shell strings. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
In scripting languages, string concatenation (also known as string concatenation or string merging) is often very simple, such as:
In PHP, use. You can concatenate two strings; in JavaScript, you can merge two strings into one by using +.
However, you don't need to use any operators in Shell, and you can concatenate two strings side by side, which is very simple and rough. Take a look at the following example:
#! / bin/bash
Name= "Shell"
Url= "http://c.biancheng.net/shell/"
There can be no spaces in the str1=$name$url#
Str2= "$name$url" # if surrounded by double quotes, there can be spaces in the middle
Another string can appear in the middle of str3=$name ":" $url#.
Str4= "$name:$url" # you can write it this way
Str5= "${name} Script:$ {url} index.html" # this time you need to put curly braces on the variable name
Echo$str1
Echo$str2
Echo$str3
Echo$str4
Echo$str5
Running result:
Shell http://c.biancheng.net/shell/
Shell http://c.biancheng.net/shell/
Shell: http://c.biancheng.net/shell/
Shell: http://c.biancheng.net/shell/
ShellScript: http://c.biancheng.net/shell/index.html
For line 7, a space cannot appear between $name and $url because when a string is not surrounded by any kind of quotation marks, the string is considered to be over when it encounters a space, and the contents after the space are parsed as other variables or commands.
For line 10, add {} to help the interpreter identify the boundaries of variables.
Shell is very similar to Python in how strings are concatenated. Python supports both concatenating strings with + and putting two strings together.
On how to carry out Shell string concatenation and merge to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.