string concatenation in bash


Results 1 to 6 of 6

Thread: string concatenation in bash

  1. #1
    Join Date
    Jan 2005
    Posts
    229

    string concatenation in bash

    How do you join two strings. I have two strings in 2 differnent vars. How can I join this and assign it to another var in bash?
    The Problem is Choice.

  2. #2
    Join Date
    Sep 2002
    Location
    Harlow, UK
    Posts
    1,788
    sed or awk?

    Can't help with any code though

    Maybe:
    Code:
    man awk
    
    -v var=value   assigns value to program variable var.
    Last edited by deathadder; 05-14-2005 at 12:45 PM.
    If you have to ask why you want to install Linux, then perhaps you shouldn't.
    -- Michael D. Watts (Gone but never forgotten)

    Linux is not Windows | Posting Guidelines

    Code Monkey (YouTube)

  3. #3
    Join Date
    Jan 2004
    Location
    Milwaukee
    Posts
    313
    Concatenation is easy and intuitive in bash:

    $ a=hip
    $ b=hop
    $ ab=$a$b
    $ echo $ab
    hiphop

    Check out the link in my sig for a great bash reference.

    drChuck
    "Well, I've been to one world fair, a picnic, and a rodeo, and that's the stupidest thing I ever heard come over a set of earphones."

  4. #4
    Join Date
    Jan 2005
    Posts
    229
    Thanks a lot. I did try that (in a different sort of way) I used
    $c= $a $b
    because I needed a space in between. Now I use
    $c= $a$space$b.
    The Problem is Choice.

  5. #5
    Join Date
    Sep 2002
    Location
    San Antonio, TX
    Posts
    2,607
    $a=cow
    $b=tipping
    $complete=$a" are not for "$b
    echo $complete
    cows are not for tipping

    hlrguy
    Were you a Windows expert the VERY first time you looked at a computer with Windows, or did it take a little time.....
    My Linux Blog
    Linux Native Replacements for Windows Programs
    Mandriva One on a "Vista Home Barely" T3640 E-Machine runs great.

  6. #6
    Join Date
    Apr 2012
    Posts
    1
    Quote Originally Posted by hlrguy View Post
    $a=cow
    $b=tipping
    $complete=$a" are not for "$b
    echo $complete
    cows are not for tipping

    hlrguy
    Your example magically makes "cow" plural? ;-p

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •