LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-01-2015, 11:02 AM   #1
newuser85
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.

#!/usr/bin/sh

pl="lsapps"
LAWDIR='E:\VHA_Script\Scripts\'
localdir=$LAWDIR\$p1\work\NTCONIN

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, 11:18 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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, 10:29 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
I agree with 1 & 2 above.
Also the '\' before '$pl' is unneeded and acts as an escape.
Try this
Code:
pl="lsapps"
LAWDIR='E:\VHA_Script\Scripts\'
localdir=${LAWDIR}${pl}\\work\\NTCONIN


echo $localdir

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

Original Poster
Rep: Reputation: Disabled
Hi,

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.
 
  


Reply


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


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