LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-11-2003, 09:17 AM   #1
FireAge
LQ Newbie
 
Registered: Jun 2002
Location: Groningen, The Netherlands
Distribution: Redhat 7.3
Posts: 13

Rep: Reputation: 0
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???
 
Old 03-11-2003, 09:26 AM   #2
acid2000
Member
 
Registered: Nov 2001
Location: Exeter, UK
Distribution: Gentoo 1.4
Posts: 243

Rep: Reputation: 30
+ is a java string operator not a bash script operator

Try

#!/bin/bash

APE=ape
BEAR=bear
APEBEAR=`echo $APE $BEAR`
echo $APEBEAR
 
Old 03-11-2003, 09:36 AM   #3
FireAge
LQ Newbie
 
Registered: Jun 2002
Location: Groningen, The Netherlands
Distribution: Redhat 7.3
Posts: 13

Original Poster
Rep: Reputation: 0
Okay but that would yield: "ape bear" as result, not "apebear"
 
Old 03-11-2003, 09:52 AM   #4
FireAge
LQ Newbie
 
Registered: Jun 2002
Location: Groningen, The Netherlands
Distribution: Redhat 7.3
Posts: 13

Original Poster
Rep: Reputation: 0
nevermind, found it after all:

APE=ape
BEAR=bear
APEBEAR=$APE$BEAR
 
Old 03-11-2003, 10:57 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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}.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script help (arrays and strings from files) nkoplm Programming 14 12-02-2005 09:50 AM
Bash scripting: column-ize file of varying length strings Quantum0726 Programming 4 08-13-2005 06:19 PM
BASH: Output everything between two strings systemparadox Programming 2 12-18-2004 10:26 AM
bash and strings graziano1968 Linux - Software 2 10-01-2004 06:50 AM
adding strings pantera Programming 5 08-20-2004 08:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration