LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-27-2017, 07:03 AM   #1
massy
Member
 
Registered: Nov 2013
Distribution: CentOS 6.4
Posts: 209
Blog Entries: 1

Rep: Reputation: Disabled
expanding a variable in another


I have an script that it gets a command from the user. Sometimes I need to using a variable in the command. The variable is defined in a script, before it. like this:

#!/bin/bash
...
line=`echo $a|cut -d',' -f1`
...

and after run the script I answer this to a question:
Enter a command:/.../zm ... theAttr $line


This command should be used in a ssh,...
Now, when I echo the command it doesn't expand the $line. It echos $line rather than the amount of it!
 
Old 12-27-2017, 08:21 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,590

Rep: Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353
would be nice to see more lines of your code.
But anyway it looks like a dangerous solution.
 
Old 12-27-2017, 08:34 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,533

Rep: Reputation: 3138Reputation: 3138Reputation: 3138Reputation: 3138Reputation: 3138Reputation: 3138Reputation: 3138Reputation: 3138Reputation: 3138Reputation: 3138Reputation: 3138
I agree there is no way to provide help with the information provided or without looking at your bash script.

We do not know how $a is set nor the entered command nor how the command or $line is used in ssh.
 
Old 12-27-2017, 01:47 PM   #4
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware, OpenBSD
Posts: 4,044
Blog Entries: 11

Rep: Reputation: 2233Reputation: 2233Reputation: 2233Reputation: 2233Reputation: 2233Reputation: 2233Reputation: 2233Reputation: 2233Reputation: 2233Reputation: 2233Reputation: 2233
You could try looking up bash's eval command.
 
  


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
Expanding a variable within a variable larrycohen28 Programming 3 01-15-2014 03:10 AM
[SOLVED] trouble expanding 4+TB GPT partition after expanding hardware RAID-5 volume muad'dib Linux - Enterprise 6 09-26-2009 06:01 PM
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 01:08 AM
expanding variable in shell script dipenchaudhary Programming 8 02-08-2006 06:05 PM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 06:17 PM

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

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