Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-12-2009, 05:46 AM   #1
Registered: May 2007
Location: Bulgaria
Distribution: Slackware, SCO Unix
Posts: 62

Rep: Reputation: 20
How to concatenate strings in Shell

Hello, I'm trying to create a wrapper script around texttops filter in CUPS. The original texttops accepts 6 arguments:

texttops $job-id $user $title $copies $options $file

The fifth argument are user options passed true lp command (lp -o landscape -o cpi=15).The problem is, that the fifth argument arrives to texttops like concatenated strings:

"landscape cpi=15 lpi=12"

In my wrapper script, I'm changing some of this options, but when I'm trying to pass them to texttops, it does not accept them as one string. Here what I've done so far:


eval set -A opt "$options" # array

for opt in ${opt[@]}; do
case $opt in

newoptions=$add" "$newoptions


( eval texttops $job-id $user $title $copies "$newoptions" $file )

The problem is, that $newoptions is not recognised like one string but like several, and when I'm trying to pass them to texttops, it returns an error. The script returns something like this (7 arguments, instead of 6):

texttops 1 root no-title 1 landscape lpi=12 /tmp/file-to-print

The "landscape" and "lpi" are not recognised as one string, so texttops assumes that "lpi=12" is the name of the file.

Any ideas, how to concatenate newoptions, so it will be recognised as one string?
Old 12-12-2009, 05:58 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
[mherring@Ath play]$ str1="the quick"
[mherring@Ath play]$ str2="brown fox"
[mherring@Ath play]$ str3="$str1 $str2"
[mherring@Ath play]$ echo $str3
the quick brown fox
[mherring@Ath play]$
1 members found this post helpful.
Old 12-12-2009, 06:07 AM   #3
Registered: May 2007
Location: Bulgaria
Distribution: Slackware, SCO Unix
Posts: 62

Original Poster
Rep: Reputation: 20
Thanks man, I've changed it like that:

texttops $job $user $title $copies "\"$newoptions"\" $file

Works like charm.

Last edited by kofucii; 12-12-2009 at 06:08 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
compare strings in shell scripting culin Linux - General 10 01-24-2013 02:33 AM
How to concatenate two strings into one string in B-shell? jimmyjiang Red Hat 5 01-08-2008 02:15 PM
comparing 2 strings in shell script dhanabalanb Programming 3 08-01-2007 02:17 PM
Shell Script Strings - trim revof11 Programming 3 11-30-2006 10:46 AM
Need shell script to concatenate a string and a variable into a directory name AwesomeMachine Linux - Newbie 2 05-07-2006 04:42 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:42 PM.

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