Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-01-2015, 10:02 AM   #1
LQ Newbie
Registered: Aug 2015
Posts: 15

Rep: Reputation: Disabled
concatenate couple of variable's holding path details

Hi All,

I am trying to concatenate two variables in shell script holding path details and then appending one more path to it.



echo $localdir


Output - E:\VHA_Script\Scripts\$p1workNTCONIN

but my expectation is to get E:\VHA_Script\Scripts\lsapps\work\NTCONIN (Path) stored in localdir


Fyi I am running the script on Cygwin. need your advice to resolve the issue. Thanks in advance.
Old 09-01-2015, 10:18 AM   #2
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,147

Rep: Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887
1. the path looks weird (ms-windows ?)

2. pl != p1

3. i think you would need to quote "$p1" so that the shell doesnt interpret the variable name as $p1work.
Old 09-01-2015, 09:29 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
I agree with 1 & 2 above.
Also the '\' before '$pl' is unneeded and acts as an escape.
Try this

echo $localdir

bash t.t
Note the extra '\'s to make '\' a literal char instead of the escape-metachar
1 members found this post helpful.
Old 09-02-2015, 04:16 AM   #4
LQ Newbie
Registered: Aug 2015
Posts: 15

Original Poster
Rep: Reputation: Disabled

Thanks for both of you.

1) Yes I am trying to execute the script on Windows using Cygwin.

2) Typo corrected.

3) tried localdir=${LAWDIR}${pl}\\work\\NTCONIN and now value is getting stored as expected.


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
[SOLVED] Concatenate two strings to form a VARIABLE NAME jeethapj Programming 6 05-04-2015 11:03 PM
Concatenate variable w/ path string ... spaghettios Linux - Newbie 4 07-22-2012 05:50 PM
concatenate variable names in bash xeon123 Linux - Newbie 4 04-07-2011 08:01 PM
Need shell script to concatenate a string and a variable into a directory name AwesomeMachine Linux - Newbie 2 05-07-2006 03:42 AM
how to concatenate variable name in Java ? black Programming 1 11-16-2004 04:08 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration