LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-09-2016, 08:45 PM   #1
gglq000
Member
 
Registered: Mar 2012
Posts: 65

Rep: Reputation: Disabled
how to evaluate variable values, details inside


I needed to create array of commands and execute it. However due to some of the commands having space, I had to enclose in single quotes. The only issue is within each commands there are variable that should be evaluated to its values during execution which apparently not happening because I enclosed in single-quotes. Any way to evaluate those during loop?

TOOL_COMMANDS=(\
'cd $LINPACK_LOC' \
'nohup tar -xvf $LINPACK_LOC/$LINPACK_NAME' \
'mv $LINPACK_LOC/$LINPACK_INSTALL_DIR_NAME $LINPACK_LOC/linpack' \



for i in "${TOOL_COMMANDS[@]}"
do
echo command: $i
# $i
done

output:
executing commands needed to setup tools:
command: cd $LINPACK_LOC
command: nohup tar -xvf $LINPACK_LOC/$LINPACK_NAME
command: mv $LINPACK_LOC/$LINPACK_INSTALL_DIR_NAME $LINPACK_LOC/linpack
command: cd $PMEMTEST_LOC
command: nohup tar -xvf /$PMEMTEST_LOC/$SYSDIAG_NAME
 
Old 06-10-2016, 12:41 AM   #2
lazardo
Member
 
Registered: Feb 2010
Location: SD Bay Area
Posts: 274

Rep: Reputation: Disabled
[ ? Single quotes prevent variable substitution ]
[ ? Missing closing ')' ]
[ ? CODE tags around code when posting ]

[ bash 4.3 ]
Code:
$ subme=123
$ test=(
   "its a test"
   for
   "${subme} abc ${subme}"
)

$ for i in "${test[@]}"; do echo $i; done
its a test
for
123 abc 123
$
Cheers,

Last edited by lazardo; 06-10-2016 at 12:44 AM.
 
Old 06-10-2016, 10:55 AM   #3
gglq000
Member
 
Registered: Mar 2012
Posts: 65

Original Poster
Rep: Reputation: Disabled
thanks, so single and double quotes differ in linux shell huh.
in my case, perils of using python where single and double quotes are same.
 
  


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
tcl procedures and changing variable values inside a procedure Jykke Programming 0 01-22-2015 09:44 AM
not able to evaluate variable mrajdeep Linux - Newbie 12 09-26-2013 05:57 PM
[SOLVED] How to evaluate the value of a variable ? 915086731 Linux - General 4 08-11-2011 05:03 AM
[bash] re-evaluate variable inside variable muzzol Programming 9 12-01-2010 11:31 AM
Need to define arithmetic functions and evaluate with different values david.karr Linux - Software 2 02-17-2009 11:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:45 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