LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 10: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, 10:18 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 04: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



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
[SOLVED] 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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:52 PM.

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