LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   adding strings in bash (https://www.linuxquestions.org/questions/linux-general-1/adding-strings-in-bash-49275/)

FireAge 03-11-2003 09:17 AM

adding strings in bash
 
Here's my problem.

#!/bin/bash

$APE=ape
$BEAR=bear
$APEBEAR=$APE + $BEAR <--- will not work

how do you do this?
I can't seem to find how to add two strings???

acid2000 03-11-2003 09:26 AM

+ is a java string operator not a bash script operator

Try

#!/bin/bash

APE=ape
BEAR=bear
APEBEAR=`echo $APE $BEAR`
echo $APEBEAR

FireAge 03-11-2003 09:36 AM

Okay but that would yield: "ape bear" as result, not "apebear"

FireAge 03-11-2003 09:52 AM

nevermind, found it after all:

APE=ape
BEAR=bear
APEBEAR=$APE$BEAR

unSpawn 03-11-2003 10:57 AM

OT, but it's better to use enclosing quotes or braces to shield your variables from breaking (due to you shell's ${IFS}): APEBEAR=${APE}${BEAR}.


All times are GMT -5. The time now is 02:56 AM.