Show
How to concatenate two strings or several strings into one string in B-shell? like connect "summer" and "winter" to "summerwinter"?
#!/bin/sh
season1='summer'
season2='winter'
echo "[${season1}] + [${season2}] = [${season1}${season2}]"
Thanks so much!!! it works great. Previous Thread | Next Thread
8 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & AnswersConcatenate strings in a a for loophi guys, I have this question. I am creating an script to that read a text file(.ini) with the list of the patterns to find for example: EPMS_VO EMPS_PARTS Then it check if file have been delivered in a folder and process it with each pattern, but I am having problems concatenting the... (7 Replies) Discussion started by: Danman7 Replies
2. Shell Programming and ScriptingConcatenate stringsHi,I'm trying to concatenate @example.com to each line of a file f1.txt. and push it into f2.txt. Here is the code i'm using. for i in `cat /home/linux1/xxxxxxx/f1.txt`; do echo ${i}@example.com > /home/linux1/xxxxxx/f2.txt; done But above code only printing @example.com in f2.txt. what... (18 Replies) Discussion started by: sam_bd18 Replies
3. ProgrammingConcatenate two stringsHello! Can anyone explain line 28 for me? I was thinking *a would be replaced by *b, but it actually appends *a to *b. I know it is related to pointer address, but could not figure it out by myself. Thanks a lot! 1 //Concatenate two strings 2 3 #include<stdio.h> 4 char *stradd (char *,... (5 Replies) Discussion started by: yifangt5 Replies
4. Shell Programming and ScriptingSearch for string in a file, extract two another strings and concatenate to a variableI have a file with <suit:run date="Trump Tue 06/19/2012 11:41 AM EDT" machine="garg-ln" build="19921" level="beta" release="6.1.5" os="Linux"> Need to find word "build" then extract build number, which is 19921 also release number, which is 6.1.5 then concatenate them to one variable as... (6 Replies) Discussion started by: garg6 Replies
5. Shell Programming and ScriptingConcatenate text between patterns in individual stringsIn any given file, wherever a certain data block exists I need to concatenate the values(text after each "=" sign) from that block. in that block. The block starts and ends with specific pattern, say BEGIN DS and END DS respectively. The block size may vary. A file will have multiple such blocks.... (12 Replies) Discussion started by: Prev12 Replies
6. Web DevelopmentConcatenate Stringshi..:) this is my sample part of my program.. $csv_output .= $row.",". $row.",". $row.",". $row.",". $row.",". ... (2 Replies) Discussion started by: Jeneca2 Replies
7. UNIX for Dummies Questions & Answersconcatenate stringsif i use echo "ravi" echo "sankar" it showing output ravi sankar but i want output as ravi sankar remember sankar should be in another echo statement only (2 Replies) Discussion started by: shankr32 Replies
8. UNIX for Dummies Questions & AnswersConcatenate StringsHi Friends, I have a requirement I need to concatenate the below two strings. String 1 = /@jobid_at_ String 2 = value stored in ORACLE_SID String 3 = string1 concatenated with String 2. Please let me know how should i do it in UNIX. Thanks, (2 Replies) Discussion started by: diva_thilak2 Replies
All times are GMT -4. The time now is 01:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved. Privacy Policy Brief: This example will help you to concatenate two or more strings variable in a bash script. This tutorial helps you with multiple shell script examples of concatenating strings in a shell script. The first example is a general way to concatenate variables of string. You can simply write all the variable one after another: #!/bin/bash # Shell program to concatenate two strings in variable str1="Welcome " str2="TecAdmin!" str3=$str1$str2 echo $str3
Output: Welcome TecAdmin!Another ExampleYou can also use += operator to concatenate two strings and store results in the first string. #!/bin/bash str1="Welcome " str2="TecAdmin!" str1+=$str2 echo $str1 Output: Welcome TecAdmin!One More ExampleUse another example with one string variable with user input and another fixed strings. #!/bin/bash # Shell program to concatenate two strings read -p "Enter your name: " name echo "Welcome $str1"
Script execution result: Enter your name: Rahul Welcome RahulUsing {} with VariablesIn some situation, you may face issue while concatenating one string with another string variable as shown in below example. Here you need to use curly braces around variable name. #!/bin/bash filename="backup" echo "$filename_03132018.sql" ### This will not work echo "${filename}_03132018.sql" ### Correct
Output .sql backup_03132018.sqlYou can see that first output if incorrect and second output is correct using {} around variable name. Updated on May 25, 2021 |